Streams
Transform constructor
Create a stream with a transform implementation and optional object mode. Local Node 22.16.0; production target compatibility pending. See https://nodejs.org/download/release/v22.16.0/docs/api/stream.html.
Formal Syntax & Structure
nodejs syntaxnodejs
new Transform(options)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| options | object | Stream implementation and mode options. |
Return Value
Transform
Result or receiver of the documented operation; see the linked versioned API contract.
Working Example
Example Snippetnodejs
import { Readable, Writable, Transform } from 'node:stream';import { pipeline, finished } from 'node:stream/promises';const upper = new Transform({transform(chunk, enc, done) { done(null, chunk.toString('utf8').toUpperCase()); }});let result = '';await pipeline(Readable.from(['pen\n','book\n']), upper, new Writable({write(c,e,cb){result += c.toString(); cb();}}));console.log(result.trim());