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

What is the difference between the `data` event and the `readable` event in a readable stream?

  1. 1

    data` event: Emitted by a readable stream to signal that data is available to be read. It's fired when the internal buffer has data.

  2. 2

    readableevent: Emitted when there may be data to read from the stream. It doesn't guarantee that data is immediately available and is often used with manual reading using.read()`.

Difficulty: 5/10
Topics: stream events, backpressure, mode switching

Scenario Questions

0-2 years experience
  1. 1

    You need to pipe a file stream directly to an HTTP response. Which event would you listen to to forward each chunk as it arrives, and what would change if you used the other event instead?

  2. 2

    If you attach a 'data' listener to a readable stream, what effect does that have on the stream's mode, and how would you switch it back to using the 'readable' event?

  3. 3

    When reading from a TCP socket you notice chunks arriving in irregular sizes. Which event gives you finer control over when to read, and why would you pick it?

2-5 years experience
  1. 1

    Your service processes large JSON log files line‑by‑line. Using the 'data' event caused memory spikes. Explain why moving to the 'readable' event can mitigate this and what code changes are needed.

  2. 2

    During debugging you see that a stream's 'end' never fires when you have a 'data' listener attached. What could be causing this, and how would you verify the behavior using the 'readable' event?

  3. 3

    You must implement backpressure when streaming data to a downstream API. How does handling the 'readable' event let you respect the downstream's write() return value compared to using 'data'?

5-8 years experience
  1. 1

    Design a high‑throughput log ingestion pipeline that reads from dozens of file streams concurrently. Discuss how you would orchestrate reading using 'readable' versus 'data' events to maximize throughput while keeping memory usage bounded.

  2. 2

    Your microservice must run on older Node versions that only emit 'data' and on newer versions that support async iteration. How would you abstract the stream handling to work efficiently across both, given the differences between the two events?

  3. 3

    Explain the impact on CPU and garbage collection when processing a 10 GB file using the default 'data' flowing mode versus manually pulling chunks in 'readable' mode with a custom highWaterMark.

8+ years experience
  1. 1

    The organization is migrating a legacy pipeline that heavily relies on 'data' event streams to a new architecture based on async generators and explicit backpressure. Outline a migration strategy that refactors the code, validates correctness, and ensures performance parity, referencing the semantics of 'readable' vs 'data'.

  2. 2

    Cross‑team, you need to define a streaming API contract that guarantees predictable memory usage. How would you specify the use of the 'readable' event and explicit read() calls in the API, and what guidelines would you set for downstream consumers to avoid pitfalls of the 'data' flowing mode?

Follow-up Questions

  • What happens if you add a 'data' listener after the stream has already emitted some chunks?
  • How does the highWaterMark setting influence the behavior of 'data' vs 'readable' mode?
  • Can you switch a stream from flowing back to paused mode, and what steps are required?