What are streams?

Streams are a collection of data that might not be complete and we might not fit them in memory.

When we watch an online video we use a stream. Do we need to download the whole video to watch it? the answer is no. thus the video data is not complete but we can watch the parts we want!

Imagine we are uploading a video with 12GB size. The problem is our memory is only 4GB. So how is it possible to upload such a file? the answer is that with using streams I don’t need to use my memory and load that 12GB file in my memory and I’m going to send this file chunk by chunk in a stream.

Where do we use streams in Node.js?

Some of the Node.js modules implementing a stream interface.

HTTP responses are the most common example of streams. HTTP responses are readable streams on the client and writable streams on the server. We are going to discuss different types of streams.

Image for post

Screenshot from www.freecodecamp.com

#stream #web-development #javascript #nodejs

Learn How to Work with Node.js Streams
13.25 GEEK