3 points

Express Post Request to Edit Post


dashboard

Posted by @mishka #nodejs

router.post('/:id/edit', auth.requireLogin, (req, res, next) => {
  Post.findByIdAndUpdate(req.params.id, req.body, function(err, post) {
    if(err) { console.error(err) };

     res.redirect(`/`+req.params.id);
  });
});
content_copy Copy

The url in the first line must be the same as the action in the edit form. Be aware that the findByIdAnd Update method erases previous data before replacing it.