Questions
5 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
05 / 24

How can you create a custom Transform stream in Node.js?

Difficulty: 5/10
Node.js streams, Transform API, Backpressure handling

By extending the Transform class from the stream module and implementing the _transform method to define how data should be transformed.

You can define a class that extends the class and implement the method to specify how the data is transformed.
You can now use your custom Transform stream by piping data through it:
The _transform(chunk, encoding, callback) method:
  1. 1

    Handles the transformation logic for each chunk of data.

  2. 2

    chunk is the current piece of data being transformed.

  3. 3

    callback is called when the transformation is complete.

The _flush(callback) method:
  1. 1

    Optional: It allows you to perform any cleanup or final transformations when the stream ends.

Scenario Questions

0-2 years experience

  1. 1Write a Transform stream that converts incoming text data to uppercase and explain how you'd wire it between a file read stream and a write stream.
  2. 2If you pipe a large file through your custom Transform and then to a writable, what does Node do when the internal buffer fills up?
  3. 3How would you modify your Transform to emit an error if it encounters a non‑string chunk?

2-5 years experience

  1. 1We need a Transform that parses newline‑delimited JSON from a TCP socket and emits JavaScript objects, skipping malformed lines; describe your implementation and error handling approach.
  2. 2A teammate's Transform stream is causing memory usage to climb over time; what are common causes and how would you debug the issue?
  3. 3Explain the trade‑offs of using objectMode versus binary mode for a logging pipeline that adds timestamps to each log entry.

5-8 years experience

  1. 1Design a streaming pipeline that reads CSV files, transforms each row, and writes to a database; where do you place custom Transform streams and how do you ensure backpressure flows end‑to‑end?
  2. 2Your service processes high‑throughput video chunks with a Transform that re‑encodes data; what performance considerations and stream options would you tune?
  3. 3If you must hot‑swap a Transform implementation in a running microservice without dropping data, how would you orchestrate the change safely?

8+ years experience

  1. 1Our legacy monolith uses callback‑based file processing; we want to migrate to a modern stream‑based architecture with shared custom Transform streams across teams. How would you plan the migration, define stable interfaces, and avoid breaking existing contracts?
  2. 2When multiple services depend on a common Transform library, what versioning and compatibility strategies would you enforce to prevent runtime errors at scale?
  3. 3Consider a requirement to enforce PII redaction across all data flows using a Transform stream. How would you architect a reusable, auditable component that can be injected globally while meeting regulatory compliance?

Follow-up Questions

  • What would happen if you forget to call the callback in _transform?
  • How does your Transform behave when the downstream consumer is slower than the source?
  • Can you show how you'd test error handling in this stream?
Share

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