Questions
17 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
17 / 24

How do you handle stream errors when working with async/await in Node.js?

Difficulty: 6/10
error handling, streams, async/await

When working with async/await, you can use a try...catch block to catch errors that occur during stream operations. For example, when reading from a readable stream, you can wrap the read() method call in a try...catch block to handle errors gracefully.

javascript

Scenario Questions

0-2 years experience

  1. 1You need to read a file line by line using a readable stream and process each line with an async function. How would you make sure that if the async processing throws, the stream is properly closed and the error is propagated?
  2. 2What happens if you forget to add a try/catch around an await inside a 'data' event handler of a stream? How would you observe the failure?

2-5 years experience

  1. 1We have an API endpoint that pipes an incoming HTTP request body to a downstream service using async/await. It started failing intermittently with uncaught exceptions. Walk me through how you'd debug and fix the error handling.
  2. 2Explain why using 'await stream.pipeline(...)' is preferred over manually attaching 'error' listeners, and show a code snippet handling cleanup.

5-8 years experience

  1. 1Our microservice processes a high‑volume Kafka consumer stream and writes results to a database using async/await. Under load, occasional unhandled promise rejections crash the process. How would you redesign the error handling to be resilient and avoid back‑pressure issues?
  2. 2Discuss trade‑offs between per‑chunk try/catch versus a global error handler when using async iterators over a Node.js readable stream in a latency‑sensitive service.

8+ years experience

  1. 1We are migrating a legacy callback‑based streaming ETL pipeline to async/await across multiple teams. What architectural guidelines would you set to ensure consistent error handling, observability, and graceful degradation?
  2. 2How would you design a shared library that abstracts stream error handling for both file I/O and network streams, considering versioning, testing, and cross‑team adoption?

Follow-up Questions

  • Can you sketch a minimal code snippet that demonstrates your approach?
  • What would you log or monitor in production for these errors?
  • How does your solution affect stream back‑pressure and throughput?
Share

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