Pipeline connects streams and coordinates completion and error propagation. Stream failures require cleanup across the entire chain, not just the final destination.
Before you start
You should know JavaScript promises, asynchronous errors and the distinction between a process and a request. When following a server example, identify the resource owner and the point where work completes. Try experiments locally with bounded input instead of assuming production traffic behaves like a single request.
The practical goal is to reason through this situation: A compression export should stop its file source when the HTTP destination fails. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Connect the resource chain
Identify source, transformation and destination as one owned operation, including completion and errors.
Step 2: Await coordinated completion
Use the promise pipeline form to receive completion or rejection instead of assuming pipe returns a finished export.
Step 3: Choose remaining response behavior
After HTTP headers or body bytes are sent, a new JSON error response may no longer be possible.
Worked scenario
A compression export should stop its file source when the HTTP destination fails.
import { pipeline } from 'node:stream/promises';
import { createReadStream, createWriteStream } from 'node:fs';
import { createGzip } from 'node:zlib';
await pipeline(createReadStream('input.txt'), createGzip(), createWriteStream('output.gz'));This local-file example completes only when the chain completes. Put the awaited operation inside its owner’s error boundary and decide whether a partial output file should be removed.
Common mistake
Manual piping without error coordination can leave resources open.
Verify the behavior
Fail the source, transform and destination separately. Confirm errors reject the operation and resources do not remain open.
Interview exercise
Choose pipeline’s promise form.
Answer and reasoning
Await completion, catch errors at the operation boundary and decide what response is still possible after headers are sent.
Continue learning
Compare the scenario with the Node.js interview questions and test your understanding with the Node.js MCQs. For terminology and implementation details, consult the reference material.