Questions
6 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
06 / 24

What is the `end` event in a readable stream, and how is it different from the `finish` event in a writable stream?

Difficulty: 5/10
readable streams, writable streams, event handling
  1. 1

    end event (readable stream): Emitted when there is no more data to be read from the readable stream.

  2. 2

    finish event (writable stream): Emitted when all data has been successfully written to the writable stream.

Scenario Questions

0-2 years experience

  1. 1You need to read a file line by line using a readable stream. Which event do you listen for to know when the file is completely read?
  2. 2If you pipe a readable stream into a writable stream, which events would you attach to each side to detect when the data flow has finished?
  3. 3What happens if you try to read from a readable stream after the 'end' event has already fired?

2-5 years experience

  1. 1During a feature you added a transformation pipeline using streams, the process hangs after the source stream finishes. How would you debug it, and what role does the 'finish' event play compared to 'end'?
  2. 2A client receives an incomplete response when you stream large JSON data. Explain how you would use 'end' and 'finish' events to ensure the response is fully sent.
  3. 3If a writable stream's 'finish' event fires but the underlying file is still empty, what could be causing that, and how does it differ from a readable stream's 'end' event?

5-8 years experience

  1. 1Design a high‑throughput log aggregation service that reads from many source streams and writes to a central store. How would you coordinate 'end' and 'finish' events across those streams to guarantee no data loss?
  2. 2When implementing back‑pressure handling, explain how the timing of 'end' versus 'finish' events affects resource cleanup and why you might need custom logic.
  3. 3In a microservice that streams data to another service over HTTP, discuss how you would handle premature termination and differentiate between readable 'end' and writable 'finish' to send proper status codes.

8+ years experience

  1. 1Our platform is migrating legacy callback‑based stream handling to async/await and promises. Outline a strategy for abstracting 'end' and 'finish' events to provide a unified completion API across services.
  2. 2When designing a cross‑team streaming library, how would you expose event semantics to avoid confusion between readable 'end' and writable 'finish', and what documentation or type definitions would you enforce?
  3. 3Consider a scenario where we need to support both Node.js streams and the Web Streams API. How would you map 'end' and 'finish' semantics to ensure consistent behavior across runtimes?

Follow-up Questions

  • Can you give an example where listening to the wrong event caused a bug?
  • How would you handle an error that occurs after the 'end' event has been emitted?
  • What happens if you never call stream.end() on a writable stream?
Share

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