Do I need to call next() after res.send()?

后端 未结 2 2020
遇见更好的自我
遇见更好的自我 2021-02-18 22:03

If I called res.send(), but didn\'t call next():

  1. Any middleware after this middleware won\'t be executed.
  2. If this middleware is
相关标签:
2条回答
  • 2021-02-18 22:47

    You don't need to call next() to finish sending the response. res.send() or res.json() should end all writing to the response stream and send the response.

    However, you absolutely can call next() if you want to do further processing after the response is sent, just make sure you don't write to the response stream after you call res.send().

    0 讨论(0)
  • 2021-02-18 23:05

    Simply

    1. All the middlewares use same request and response objects, so if you send the response via any middleware all next middlewares will be skipped
    2. You can still execute further operations by calling next(); but you can't do res.send() or res.json() further
    0 讨论(0)
提交回复
热议问题