Difference between response.send and response.write in node js

后端 未结 4 603
耶瑟儿~
耶瑟儿~ 2020-12-01 01:31

I have written a small API which uses the Node js \"restify\" framework. This API receives a request (actually anything after \"/\") and then send that request to another se

4条回答
  •  时光取名叫无心
    2020-12-01 01:48

    I was trying to send huge text data(295mb) over http using res.send(data) and res.write(data). I noticed that res.send(data) is slower than res.write(data). I observed following things.

    res.send(data): it can be called only once and it sends data in chunk of some buffer size to client and then again comes back and sends another chunk of buffer size so there is a lot of back and forth http communication.

    res.write(data): It can be called multiple times followed by res.end() and It creates buffer size based on whole data and sends over http so it would be faster in case of huge amount of data.

提交回复
热议问题