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

What is the purpose of the `unpipe()` method in Node.js streams, and how does it work?

Difficulty: 5/10
stream lifecycle, error handling, backpressure

The unpipe() method in Node.js streams is used to detach a writable stream from a readable stream. This essentially stops the flow of data from the readable stream into the writable stream, undoing the connection that was established using .pipe()

Purpose of unpipe()
  1. 1

    Stop Data Flow: It halts the automatic data transfer between streams that were connected via .pipe()

  2. 2

    Fine-Grained Control: If multiple writable streams are piped from a single readable stream, unpipe() can be used to detach a specific writable stream without affecting the others

  3. 3

    Prevent Memory Leaks or Errors: It ensures no unnecessary data transfer continues, especially if a writable stream is no longer valid or needs to be closed.

javascript
  1. 1

    If you pipe a stream to multiple destinations, with a specified stream will detach only that destination.

  2. 2

    Using unpipe() without arguments stops all piping to writable streams.

  3. 3

    unpipe event is emitted by the readable stream whenever a pipe is undone. You can add a listener for it:

Scenario Questions

0-2 years experience

  1. 1If you have a readable stream piped into a writable stream and you need to stop the flow after a certain condition, how would you use `unpipe()`?
  2. 2What happens to the data events on the source stream after you call `source.unpipe(destination)`?

2-5 years experience

  1. 1In a file upload service you pipe the request stream into a virus‑scan stream and then into a storage stream. The upload hangs when the client aborts. How would you use `unpipe()` to clean up the pipeline?
  2. 2You notice that an error emitted from a transform stream doesn't propagate to the final writable. Explain how you would modify the piping logic with `unpipe()` to ensure proper error handling.

5-8 years experience

  1. 1Design a streaming architecture where multiple downstream consumers can be attached or detached at runtime. How does `unpipe()` factor into managing backpressure and resource cleanup?
  2. 2When scaling a Node.js microservice that processes large video files via a chain of streams, what are the performance implications of forgetting to call `unpipe()` after a consumer finishes, and how would you mitigate them?

8+ years experience

  1. 1Your organization is migrating legacy callback‑based file processing to a unified stream pipeline across several services. What guidelines would you set for using `unpipe()` to avoid memory leaks and ensure graceful shutdown in production?
  2. 2In a multi‑team platform that streams telemetry data to various analytics services, how would you architect the stream management layer to handle dynamic subscription/unsubscription, and what role does `unpipe()` play in the overall reliability strategy?

Follow-up Questions

  • What events are emitted on the source and destination when `unpipe()` is called?
  • How does `unpipe()` affect backpressure handling in a pipeline?
  • What would happen if you called `unpipe()` on a stream that wasn't piped?
Share

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