Questions
4 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
04 / 24

Create a readable stream

Here's how you can do it:

A readable stream is typically used to handle input, such as reading from a file or generating data programmatically. For example:
Readable streams can be consumed in three ways: using event listeners, the method, or async iterators. Here are examples:
Difficulty: 5/10
Topics: custom readable streams, backpressure, stream piping

Scenario Questions

0-2 years experience
  1. 1

    How would you implement a simple readable stream that emits the numbers 1 through 10?

  2. 2

    If you pipe that readable stream into a writable file stream and the file system is slower than the data generation, what does Node do?

2-5 years experience
  1. 1

    We need to process a large CSV file line‑by‑line without loading it all into memory. How would you set up a readable stream for this, and which options would you tune?

  2. 2

    During a recent deployment the stream started throwing 'ERR_STREAM_DESTROYED' errors. What could cause that, and how would you go about debugging it?

5-8 years experience
  1. 1

    Our service reads HTTP request bodies using a custom readable stream that throttles data based on downstream processing speed. How would you design backpressure handling, and what trade‑offs does it introduce?

  2. 2

    We want to replace a legacy event‑emitter pipeline with a Node.js readable stream to reduce memory usage. What architectural changes and edge cases must you consider?

  3. 3

    If the stream must support both object mode and binary mode depending on runtime configuration, how would you implement that without breaking existing consumers?

8+ years experience
  1. 1

    At a platform level we plan to stitch together multiple microservices via Node.js streams for a data ingestion platform. How would you design stream boundaries, error propagation, and versioning to ensure long‑term maintainability?

  2. 2

    Our monolith currently writes logs synchronously. We want to migrate to an async, back‑pressured streaming logger used across all services. What migration strategy would you propose and how would you mitigate risk?

  3. 3

    Considering cross‑team usage, how would you expose a reusable readable‑stream library that handles backpressure, cancellation, and monitoring while keeping the API stable for future Node versions?

Follow-up Questions

  • What would you change if the data source was asynchronous, like a database query?
  • How does Node decide when to pause or resume a readable stream?
  • Can you describe how you would test that your stream correctly handles backpressure?