What if you could watch a movie instantly without waiting for the whole file to download?
Why Stream types (Readable, Writable, Transform, Duplex) in Node.js? - Purpose & Use Cases
Imagine you have a huge file to process, like a video or a large log file, and you try to load it all at once into memory to work on it.
Loading everything at once can crash your program or slow it down a lot. Also, handling data piece by piece manually is tricky and messy, making your code hard to read and maintain.
Node.js streams let you handle data bit by bit as it flows, so you don't need to wait for everything to load. They make reading, writing, and transforming data smooth and efficient.
const fs = require('fs'); const data = fs.readFileSync('bigfile.txt'); processData(data);
const fs = require('fs'); const stream = fs.createReadStream('bigfile.txt'); stream.on('data', chunk => processData(chunk));
Streams enable efficient, memory-friendly processing of large or continuous data, making apps faster and more responsive.
Streaming a movie online without downloading the whole file first, so you can start watching immediately while the rest loads.
Streams handle data in small chunks, not all at once.
They come in types: Readable, Writable, Transform, and Duplex for different tasks.
Using streams makes your app faster and less likely to crash with big data.