Why can't we do multiple response.send in Express.js?

后端 未结 2 2099
萌比男神i
萌比男神i 2020-12-08 10:01

3 years ago I could do multiple res.send in express.js.
even write a setTimeout to show up a live output.

response.send(\'

        
2条回答
  •  情歌与酒
    2020-12-08 10:28

    Maybe you need: response.write

    response.write("foo");
    response.write("bar");
    //...
    response.end()
    

    res.send implicitly calls res.write followed by res.end. If you call res.send multiple times, it will work the first time. However, since the first res.send call ends the response, you cannot add anything to the response.

提交回复
热议问题