Questions
7 of 24
1What are streams?
2List elementary stream types.
3What are advantages of streams.
4Create a readable stream
5How can you create a custom Transform stream in Node.js?
6What is the `end` event in a readable stream, and how is it different from the `finish` event in a writable stream?
7How can you handle errors in Node.js streams?
8Explain the concept of object streams and provide an example use case.
9Explain the difference between `ObjectMode` and `Buffer` mode in a readable stream.
10Explain the difference between a flowing and a non-flowing readable stream.
11What is the difference between the `data` event and the `readable` event in a readable stream?
12How can you handle cleanup operations when working with streams?
13What is the purpose of the `highWaterMark` option when creating a readable stream?
14What is backpressure in Node.js streams, and how can you handle it?
15What is the pause() method used for in a readable stream, and how can you resume data flow?
16What is the purpose of the `stream.finished()` utility in Node.js?
17How do you handle stream errors when working with async/await in Node.js?
18How can you handle memory usage when dealing with large files in Node.js streams?
19Explain the concept of piping in Node.js streams.
20What is the purpose of pipeThrough function
21What is the purpose of the `unpipe()` method in Node.js streams, and how does it work?
22Explain the difference between `pipe()` and `on('data')` when working with streams.
23What is the purpose of the `stream.pipeline()` function in Node.js?
24write code of a stream to read a local file in node js
07 / 24

How can you handle errors in Node.js streams?

Difficulty: 5/10
error handling, stream events, pipeline
  1. 1

    By listening for the error event on the stream instances.

  2. 2

    Additionally, you can use try-catch blocks when working with streams to catch synchronous errors.

javascript

Scenario Questions

0-2 years experience

  1. 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?
  2. 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

  1. 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?
  2. 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

  1. 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?
  2. 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

  1. 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?
  2. 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?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.