Working with streams in NodeJS

What are Streams ? Streams are just collections of data that is sent in small chunks, and it also don’t have to fit in memory. Meaning, when dealing with big chunk of data either read or write, the memory usage is less consumed, which is extremely useful. let me show two examples how streams can be optimized the memory consumption. writeStream.js const fs = require('fs'); const file = fs.createWriteStream('file.txt'); for(let i=0; i<=2e6; i++) { file....

April 17, 2019 · 2 min