What is the difference between res.send and res.write in express?

前端 未结 4 476
挽巷
挽巷 2020-12-04 19:27

I am a beginner to express.js and I am trying to understand the difference between res.send and res.write ?

4条回答
  •  天命终不由人
    2020-12-04 20:01

    res.send is equivalent to res.write + res.end So the key difference is res.send can be called only once where as res.write can be called multiple times followed by a res.end.

    But apart from that res.send is part of Express. It can automatically detect the length of response header. But there may be be a chance of memory spike with res.send(), in case of large files, our application hangs in between .

提交回复
热议问题