Node.js Stream

Node.js stream documentation.

I used to open and read Node.js documentation whenever I don’t have much to do in my early days of learning web development. In these docs pages, I saw a word mentioned quite a lot throughout it called “stream”. I don’t know what it means at the time as I thought only about the concept of “media streaming” such as YouTube. But the further I go, I see that stream is a much lower concept than what I thought before. Streams are basically everywhere in Node.js. HTTP’s request and response object are readable stream and writable stream respectively (in respect to server). You can also create a stream to and from a file to read or write it. Since then, I have this feeling that stream is quite essential in Node.js. Therefore studying it in a deeper manner could help me elevate my Node.js skill.

Now that I’m here, I can say that streams are truly one of the core concept of Node.js aside from event emitters. Streams are basically the same as what people may have thought about it in regards of media streaming, they are small bits of data that are sent over a period of time from source to destination. Imagine sending a video from two different places. Rather than having the source to send everything in one go, resulting in a huge chunk load of data that is slowing the traffic, we can send only one small piece at a time in order to send it faster, with lighter traffic, and most importantly can be consumed right away by the consumer.

This also offers a good advantage to servers too. If the server were to send a single big data in one go, it has to be saved somewhere before the package is ready. Where does it store it while the server reads the file up? Yes, the memory. it may not be the case if you were to serve only a single client, but we’re talking about a server here, boys. Of course you would expect it to serve a bunch of people in a short span of time. Now, to load a big file in one go will certainly hurt the load time, resulting in bad UX in front-end for making the user wait for its content.

Node.js stream handbook.

I know I still scratched the surface with the topic of stream, and I could’ve caught more points if I were to understand more about computers. But it’s useless to think about that since I will understand it better as I go further into computer anyway. For now, it’s enough. There is a comprehensive handbook about Node.js stream which I haven’t finished reading. That will take time for me to faithfully devour it. Again for now, I will continue with a few “basics” presented by Node in Action book. Thank you for reading my post and have a good day.

Published by YosepRA

I'm a MERN stack web developer. I will build a web application to turn your online ideas into reality.

Leave a comment

Design a site like this with WordPress.com
Get started