3 points

Express Post Request to Edit Post


PHOTO EMBED

Saved 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_copyCOPY

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.