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

288
Views
How to solve: Error: Route.get() requires a callback function but got a [object Object]?

Routes Folder Structure

Note: There was no problem, until I added docs_router.js
routes folder structure


docs_router.js

const { control_docs_v1, ipManager } = require('../controllers/indexer')
const router = require('express').Router()
router.get('/v1', ipManager, control_docs_v1)
module.exports = router

location.js

const { ipManager, sendData } = require('../controllers/indexer')
const router = require('express').Router()
router.get('/weather/:loc', ipManager, sendData)
module.exports = router

indexer.js

const location = require('./location')
const docs_router = require("./docs_router")

module.exports = {
    location,
    docs_router
}

In the entry file, index.js I have,

app.use("path1", location)
app.use("path", docs_router)

Is there any issue with exporting multiple router object? How to use router in righth way?

What I want to achieve

  • I want to keep the routes for specific features in separate files.
  • I want only one file to export everything from the routes folder
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Finally solved. I made these changes.


docs_router.js

const { control_docs_v1, ipManager } = require('../controllers/indexer')
const router = require('express').Router()
router.get('/v1', ipManager.ipManager, control_docs_v1.control_docs_v1)
module.exports = router

location.js

const { ipManager, sendData } = require('../controllers/indexer')
const router = require('express').Router()
router.get('/weather/:loc', ipManager.ipManager, sendData)
module.exports = router

Doing this resolved the error.

about 4 years ago · Juan Pablo Isaza Report
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!