Stream to an HTTP Response with Node.js

Опубликовано: 21 Январь 2021
на канале: Hey Node
5,402
63

See the written version of this tutorial for links to prerequisites and related tutorials: https://heynode.com/tutorial/stream-h...

In this tutorial we will use streams to efficiently send a large file as an HTTP response in a Node.js application. Reading a large file into memory before sending it back as a response is an inefficient use of time and resources. We can create a readstream from a file and pipe it directly to an HTTP response body, significantly reducing the memory footprint and time required to serve the file.

By the end of this tutorial, you should be able to:

Understand streaming to a response body
Implement fs.createReadStream and pipe the content into an HTTP response

Heynode.com: The best online Node.js courses and tutorials to help you solve hard problems fast.