Practise the vocabulary of modern Node.js Streams — stream.pipeline() for safe error propagation, stream.compose() for reusable pipeline units, Readable.from() for async iterables, and abort signal cancellation.
0 / 5 completed
1 / 5
What does stream.pipeline() do compared to manually piping streams?
stream.pipeline() connects streams end-to-end and handles error propagation and cleanup automatically. If any stream emits an error, all other streams in the pipeline are destroyed. This avoids the common bug with .pipe() where an error in a middle transform leaks the destination stream.
2 / 5
What does stream.compose() do in Node.js?
stream.compose() takes a list of streams and returns a new duplex stream where writing goes into the first and reading comes out of the last. The intermediate streams are hidden. This enables building reusable stream pipelines that can be composed further — e.g., a gzip-then-encrypt transform that looks like a single transform.
3 / 5
How can an AsyncGenerator function serve as a readable stream source in Node.js?
Readable.from() accepts any iterable or async iterable (including async generators) and wraps it in a Readable stream. The generator's yielded values become stream chunks. This makes it easy to produce streaming data with familiar async/await syntax: Readable.from(generateRows(db)).
4 / 5
What does Readable.from() accept as its argument?
Readable.from(iterable) is a factory that converts any iterable (sync or async) into an object-mode readable stream. It handles both the sync [Symbol.iterator] and async [Symbol.asyncIterator] protocols, making it versatile for arrays, generators, database cursors, and more.
5 / 5
How does passing an AbortSignal to stream.pipeline() work?
Since Node.js 16, stream.pipeline() accepts an options object with an signal property: pipeline(src, transform, dest, { signal }, callback). When signal.abort() is called, all streams in the pipeline are destroyed with an AbortError, enabling clean cancellation of long-running stream operations.