Testing REST routes with curl -X PUT, returns 404 Testing REST routes with curl -X PUT, returns 404 express express

Testing REST routes with curl -X PUT, returns 404


Restarting the node server solved the problem for me


Did you double check that you did the previous step? Without a set router the page won't resolve.

router.put('/posts/:post/upvote', function(req, res, next) {  req.post.upvote(function(err, post){    if (err) { return next(err); }    res.json(post);  });});

That's the only thing I could think of could be the problems if you haven't had issues up until this step. Also you might check that your server can resolve via localhost, sometimes you have to use your private ip, 192.168, etc, because it depends on the network config your host has.


I think I may have an answer. I have spoken with several people who have gotten caught on this particular portion of the tutorial.

Under Opening REST Routes > Pre-Loading Objects, we are instructed to enter the following code:

router.param('post', function(req, res, next, id) {  var query = Post.findById(id);  query.exec(function(err, post) {    if (err) { return next(err); }    if (!post) { return next(new Error('can\'t find post')); }    req.post = post;    return next();  });});

However, some people are consistently leaving out the second line:

var query = Post.findById(id);

or even interpolating it into the third line:

var query.exec(function(err, post) {

This may be the very simple solution to your problem.