Express.js Routing error: Can't set headers after they are sent

前端 未结 6 2085
情歌与酒
情歌与酒 2020-12-01 05:35

I\'m not really sure why I\'m getting this error. It\'s a simple API built on express.js to be able to add and remove posts. The error occurs when I trigger the delete route

6条回答
  •  醉梦人生
    2020-12-01 06:08

    You need to add the 'return' so that you don't reply twice.

    // save post and check for errors
    post.save(function(err) {
        if (err) {
            return res.send();
        }
        res.json({ message: 'post created!' });
    });
    

提交回复
热议问题