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

What is the purpose of pipeThrough function

Piping is a mechanism for connecting a readable stream to a writable stream, allowing data to flow automatically from the source to the destination.

  1. 1

    The pipeThrough() method of the ReadableStream interface provides a chainable way of piping the current stream through a transform stream or any other writable/readable pair.

  2. 2

    Piping a stream will generally lock it for the duration of the pipe, preventing other readers from locking it.

javascript
Difficulty: 5/10
Topics: web-streams-api, transform-streams, backpressure

Scenario Questions

0-2 years experience
  1. 1

    You're fetching a large JSON file from an API and need to parse it line-by-line without loading the whole thing into memory. How would you use pipeThrough with a transform stream to do this?

  2. 2

    A teammate wrote code that does fetch(url).then(r => r.body.pipeThrough(decompress)).then(process) but it's not working. What's missing and how would you fix it?

2-5 years experience
  1. 1

    You're building a log ingestion pipeline: HTTP request → decompress → parse JSON → validate schema → write to DB. The validation step occasionally throws on malformed records. How do you structure the pipeThrough chain so bad records are logged and skipped without stopping the whole pipeline?

  2. 2

    Your team migrated from Node's legacy stream.pipeline() to Web Streams pipeThrough. After deployment, memory usage spiked on large file uploads. What's a likely cause and how would you debug it?

5-8 years experience
  1. 1

    Design a reusable TransformStream that implements rate-limiting for any pipeThrough pipeline. It should respect backpressure, allow burst tolerance, and expose metrics for observability. Walk me through the key methods you'd implement.

  2. 2

    You're streaming video transcoding output through multiple pipeThrough stages (decrypt → decode → filter → encode → encrypt). The pipeline stalls intermittently under load. How do you instrument and diagnose whether it's a backpressure deadlock, a slow transform, or buffer bloat?

8+ years experience
  1. 1

    Your org has 50+ services using a mix of legacy Node streams, Web Streams, and async iterators. You're tasked with defining a cross-team streaming standard. What criteria would you use to decide when pipeThrough is the right abstraction vs. when to allow alternatives? How do you handle gradual migration?

  2. 2

    A critical data pipeline uses pipeThrough for exactly-once processing semantics across service boundaries. The transform streams are stateful and need to survive restarts. How would you architect checkpointing and recovery without breaking the composable pipeThrough model?

Follow-up Questions

  • How does error propagation work when the transform stream throws?
  • What happens to backpressure signals when you chain multiple pipeThrough calls?
  • When would you choose pipeThrough over manually handling readable/writable events?