3 points

Express Post Request to Edit Post


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) };

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.