Handle backpressure, use stream.pipeline() safely, implement Transform streams, tune highWaterMark, and work in object mode.
0 / 5 completed
1 / 5
What is backpressure in Node.js streams and why does it matter?
Backpressure:readable.pipe(writable) handles backpressure automatically — when writable.write() returns false, pipe pauses the readable and resumes it on the drain event. Without backpressure handling, a fast file read piped to a slow network write would buffer the entire file in memory, potentially causing OOM.
2 / 5
What does stream.pipeline() provide over .pipe()?
pipeline(): with .pipe(), an error in a middle stream does not destroy the source or destination streams, causing resource leaks. stream.pipeline(source, transform, destination, callback) attaches error handlers to all streams and destroys the entire chain on error. The stream/promises version returns a Promise for use with async/await.
3 / 5
What is a Transform stream in Node.js and what method must be implemented?
Transform stream:class UpperCase extends Transform { _transform(chunk, enc, cb) { this.push(chunk.toString().toUpperCase()); cb(); } }. Transform streams implement both Readable and Writable interfaces — data flows in one end and out the other, modified. They are the building block for compression (zlib.createGzip()), encryption, and parsing stages in a pipeline.
4 / 5
What does the highWaterMark option control in Node.js streams?
highWaterMark: the default is 16KB for byte streams and 16 objects for object mode streams. When the internal buffer exceeds this threshold, write() returns false and the stream applies backpressure. Tuning it upward for large file transfers increases throughput; tuning it downward for memory-constrained environments reduces peak usage.
5 / 5
What is object mode in Node.js streams and when is it used?
Object mode: by default, streams handle Buffers or strings. Object mode allows piping JavaScript objects: a database cursor Readable emits row objects; a Transform filters them; a Writable inserts to another database. Each object counts as 1 toward the highWaterMark regardless of size. Object mode streams cannot be piped to non-object mode streams without serialisation.