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 {}.
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
