Unlock the Power of Streams: An Underrated Feature in NodeJS

Manish Prasad
Powerplay
Published in
3 min readMar 11, 2020

--

Stream is an abstract interface for working with streaming data in Node.js. Streams have gained a reputation that it is hard to work with and harder to understand. However, it is a highly underrated but very powerful concept in Node.js. This article will help in understanding streams, how to work with them and where to use this module.

Introduction

The official documentation of Node.js defines stream as an abstract interface for working with streaming data. It is one of the fundamental concepts in Node.js and is very powerful when working with large amounts of data, e.g., reading a very large file size. Streams are memory efficient as there is no need to load large amounts of data in memory instead read chunks of data piece by piece and process the contents. Also, since one doesn’t have to wait for all the data to load first, it is time-efficient too.

For a complete introduction of the Stream module and its related APIs, read the official documentation.

An example -

For the purpose of showing the powerful capability of streams, let us do the following operations.

1. Read data from a large file.
2. Filter the data.
3. Transform the input data.
4. Write the transformed data into a file.

--

--

Manish Prasad
Powerplay

In character, in manner, in style, in all things, the supreme excellence is Simplicity..! | IIT Roorkee