0

I am writing a NodeJS server with REST Api using Express. I have Users model and methods to fetch all the users:

  app.get('/api/users', function(req, res){

  User.find(function(err, users){
    if(err){ return err; }
    res.json(users);
  });
});

and a method to get a user by ID:

app.get('api/users/:id', function(req, res, next) {
  console.log("one");
  User.findById(req.params.id, function(err, user) {
    if (err)
    res.send(err);
    res.json(user);
  });
});

But when I try to send a URL parameter to get a user by ID the relevant method is not called. And req.params is {}.

Postman shows this: enter image description here

I am new to the MEAN stack so I may have overlooked some obvious mistakes. But what can be the reason for that?

EDIT:

It was a typo, I just forgot a slash

1
  • Does your get api/users route work? Commented Mar 28, 2016 at 0:36

1 Answer 1

2

make it like

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

you forget starting slash (/)

Sign up to request clarification or add additional context in comments.

1 Comment

sure, 10 mins should pass

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.