Interview frequency: …
Short answer
The types are: readable (for reading), writable (for writing), duplex (for both independently), and transform (for modifying data as it passes through).
Explanation
Streams are the core of performance in Node.js for processing huge data without loading it entirely into memory. A readable provides data and end events. A writable accepts write() and end(). A duplex has two channels for reading and writing, while a transform is a special kind of duplex where the output is modified directly based on the input.
Code example
import { pipeline } from "node:stream/promises";
await pipeline(readable, transform, writable);Common mistakes
- Reading gigabyte-sized files with fs.readFile into memory instead of using streams.
Follow-up questions
- What is the backpressure phenomenon in Node.js streams and how is it handled in engineering terms?
- How do you create and customize a Transform Stream to process data as it flows through Node.js?