我需要在res.send()之后调用next()吗? [英] Do I need to call next() after res.send()?

查看:67
本文介绍了我需要在res.send()之后调用next()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我调用了 res.send(),但没有调用 next():

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

  1. 此中间件之后的任何中间件都不会执行.
  2. 如果该中间件不是最后一个中间件,则该请求将永远挂起",并且不会被垃圾回收,因为它仍在等待 next()的调用./li>

以上是我试图说我应该始终调用 next()的说法,对吗?

The above is my attempt to argue that I should always call next(), is it true?

推荐答案

无需调用 next()即可完成发送响应. res.send() res.json()应该结束所有对响应流的写入并发送响应.

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.

但是,如果您想在发送响应后做进一步处理,您绝对可以调用 next(),只需确保您不写响应即可您调用 res.send()之后的流.

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().

这篇关于我需要在res.send()之后调用next()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆