QA
Beginner LevelNode JS

What are the 4 fundamental types of Node.js Streams (Readable, Writable, Duplex, Transform)?

❓ Interview Prompt: Explain Streams data processing, memory efficiency, 4 stream types (Readable, Writable, Duplex, Transform), and piping.

Streams process data sequentially in chunks rather than buffering entire files into RAM at once:

1
Readable: Source stream data can be read from (e.g. 'fs.createReadStream()').
2
Writable: Destination stream data can be written to (e.g. 'fs.createWriteStream()').
3
Duplex: Stream that is both Readable and Writable (e.g. TCP Net socket).
4
Transform: Duplex stream that modifies or transforms data during write/read (e.g. 'zlib.createGzip()').

Code Implementation Example

javascript
import fs from 'node:fs';
import zlib from 'node:zlib';

// Stream copy file with Gzip compression: uses flat memory!
fs.createReadStream('input.txt')
  .pipe(zlib.createGzip())
  .pipe(fs.createWriteStream('input.txt.gz'))
  .on('finish', () => console.log('File compressed via streams successfully!'));
💡Compressing files using Readable, Transform, and Writable streams.
🎯 Interview Key Takeaway

Use Streams to process large datasets sequentially, keeping Node.js memory footprint flat.

#Streams#Readable#Writable#Transform#Beginner
Back to all Node JS Questions→

More Node JS Interview Questions

Beginner LevelNode JS

How does the Node.js Event Loop work? Explain the 6 execution phases (Timers, Pending, Poll, Check, Close).

Beginner LevelNode JS

What does 'Single-Threaded, Event-Driven, Non-Blocking I/O' mean in Node.js?

Beginner LevelNode JS

What is the difference between process.nextTick() and setImmediate()?