Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Router.use() requiere una función de middleware pero obtuvo un

tengo el siguiente problema en mi codigo, tengo mi archivo index.js dentro de mi carpeta de rutas con el siguiente codigo que detallo mas abajo, pero aun tengo el module.exports = router que vi como muchas de las soluciones propuestas, da me da el siguiente error al compilar

throw new TypeError('Router.use() requiere una función de middleware pero obtuvo un '+ gettype(fn))

 const fs = require("fs") const express = require("express") const router = express.Router() const pathRouter = `${__dirname}` const removeExtension = (fileName) => { return fileName.split('.').shift() } fs.readdirSync(pathRouter).filter((file) => { const fileWithOutExt = removeExtension(file) const skip = ['index'].includes(fileWithOutExt) if (!skip) { router.use(`/${fileWithOutExt}`, require(`./${fileWithOutExt}`)) //TODO: localhost/users console.log('CARGAR RUTA ---->', fileWithOutExt) } }) router.get('*', (req, res) => { res.status(404) res.send({ error: 'Not found' }) }) module.exports = router
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!