By listening for the error event on the stream instances.
2
Additionally, you can use try-catch blocks when working with streams to catch synchronous errors.
javascript
Scenario Questions
0-2 years experience
1You need to read a large file using a readable stream and write it to another file. How would you make sure that any read errors are properly caught and the process doesn't crash?
2If a writable stream emits an 'error' event while you're piping data from a readable stream, what steps do you take to handle it and clean up resources?
2-5 years experience
1We have a Transform stream that parses JSON lines from a network socket. Occasionally malformed JSON causes the stream to emit an error. How would you modify the pipeline so that a single bad line doesn't bring down the whole stream, and you can log the error and continue processing?
2During a production incident, a file upload service using `stream.pipeline` started failing with uncaught exceptions. Walk me through how you would debug the error handling in that pipeline and what changes you might make to make it more robust.
5-8 years experience
1Our data ingestion service processes dozens of parallel streams and aggregates results. At high load, we see occasional backpressure and unhandled errors causing memory leaks. How would you design the error handling strategy across multiple streams to ensure failures are isolated and resources are reclaimed?
2Explain the trade‑offs between handling errors locally inside each stream versus using a central error handler with `pipeline` or `finished`. Which approach scales better for a microservice that streams data to multiple downstream services?
8+ years experience
1We are migrating a legacy monolithic file processing system to a distributed event‑driven architecture that uses Node.js streams across services. What architectural considerations around error propagation, retry semantics, and observability would you put in place to avoid cascading failures?
2In a multi‑team environment, some teams use callbacks for stream error handling while others use async/await with `pipeline`. How would you establish a consistent error‑handling contract and tooling to enforce it across the codebase?
Follow-up Questions
What happens if you forget to add an 'error' listener on a stream?
How does `stream.pipeline` change the way you handle errors compared to manual `pipe` chaining?
Can you give an example of propagating an error from a Transform stream to a downstream consumer?
Sharethis question
Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.