CodeZettaInterview Hub

Node.js · Streams · Mid-Level · Live Coding

How do you implement a Transform stream?

Short Interview Answer

Extend Transform and implement `_transform(chunk, enc, cb)` (and optionally `_flush`).

Detailed Explanation

Push transformed chunks, handle errors via callback, respect objectMode when needed. Keep transforms pure and fast; heavy work belongs off-thread.

Example

const { Transform } = require('stream');
new Transform({ transform(chunk, enc, cb) { cb(null, chunk.toString().toUpperCase()); } });

Did you know this answer?