Streams
new Transform()
Creates a duplex stage with a transformation between incoming and outgoing chunks. Call the transform callback once per input; an output may differ in length or be omitted. This example handles ASCII pieces, not arbitrary UTF-8 boundaries. Tested on Node.js 22.16.0. Example output (one line per entry): ["ABCD"].
Formal Syntax & Structure
nodejs syntaxnodejs
new Transform([options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| options | object | Readable/writable options and transform implementation. |
Return Value
Transform
The transform stream.
Working Example
Example Snippetnodejs
import { Readable, Transform, Writable } from 'node:stream';import { pipeline } from 'node:stream/promises';let body = '';await pipeline(Readable.from(['ab', 'cd']), new Transform({ transform(c, e, cb) { cb(null, c.toString().toUpperCase()); } }), new Writable({ write(c, e, cb) { body += c; cb(); } }));console.log(body);