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

259
Vistas
"Cannot GET /api/users/2" why is my GET request not working?

"Cannot GET /api/users/2" why is my GET request not working for a user with an id of 2?

The query http://localhost:3000/api/users works but i'm trying to find an individual user based on their id and this is not working in my code below.

const express = require('express');
const app = express();

const users = [
    [{name: 'liam', id: 1}, {name: 'jon', id: 2}]
];

app.get('/api/users', (req, res ) => {
    res.send(users);
})


app.get('/api/users:id', (req, res ) => {
    const id = parseInt(req.params.id)
    const user = users.filter(u => u.id === id) [0]
    res.send(user)
})

app.listen(3000, () => console.log('Listening on port 3000.......'));

When I do "http://localhost:3000/api/users/1" nothing displays in my browser.

I have updated the code to app.get('/api/users/:id'

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You're missing a slash:

app.get('/api/users/:id', …)

Also, you have an array-in-an-array, which is probably not what you intended. Use this:

const users = [
  {name: 'liam', id: 1}, {name: 'jon', id: 2}
];
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this app.get('/api/users/:id',..)

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