Error: Can't set headers after they are sent. - NodeJS and Express

后端 未结 2 1401
日久生厌
日久生厌 2021-01-26 03:32

I have a NodeJS Rest API where I have a user collection, besides that I do user SMS verification.

This is the controller for the POST /:id/verification

2条回答
  •  失恋的感觉
    2021-01-26 03:52

    res.json() send object to the clilent and after that you are trying to set the header with status code. So, it shows the error message. Use following code for set status and sending the content in the same time.

    res.status(500).json({ error: 'message' } /* json object*/);
    

提交回复
热议问题