Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.3K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

getIndividualTwitt:async(req,res)=>{
//...
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda