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

1.3K
Views
My req.params.id is undefined. How can I fix my route to make it work

I am testing my function getIndividualTwitt on Postman and getting undefined when I console.log the req.params.id. This is happening exclusively in this route. I would appreciate any help that you could apare.

index.js

app.use(express.json())

app.use('/profiles',require('../Server/routes/profile'))
app.use('/users',require('../Server/routes/users'))
app.use('/dashboard',require('../Server/routes/dashboard'))

routes/profiles.js

router.post('/:name',authorization,controller.createProfile)
router.get('/:id',authorization,controller.getProfile)
router.delete('/:id',authorization,controller.deleteProfile)
router.get('/twitt/:id',controller.getIndividualTwitt)

controllers/profiles.js

getIndividualTwitt:async(res,req)=>{
  try {
    console.log('hello')
    console.log(req.params.id) //prints undefined
    //const twitt=await connectTwitt.getTwitt(req.params.id)
       
    //res.send(twitt)
  } catch (error) {
    console.log(error)
  }
}

Postman request:

GET  http://localhost:3002/profiles/twitt/8
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Problem

The problem is in the order of your defined endpoints. Express execute code from top to bottom, so when you call /profiles/twitt/8 endpoint. it will find a match in the following router config:

router.get('/:id',authorization,controller.getProfile)

Solution

Reverse the order of defined endpoints, like this:

router.get('/twitt/:id',controller.getIndividualTwitt)
router.get('/:id',authorization,controller.getProfile)
over 4 years ago · Santiago Trujillo Report

0

replace argument order for request and response, req comes first:

getIndividualTwitt:async(req,res)=>{
//...
over 4 years ago · Santiago Trujillo 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!