Streams

new PassThrough()

Constructs a transform that forwards its input without changing the contents. Useful for controlled stream plumbing and observing byte counts. An extra stage still has buffering and lifecycle responsibilities. Tested on Node.js 22.16.0. Example output (one line per entry): ["sample"].

Formal Syntax & Structure

nodejs syntaxnodejs
new PassThrough([options])

Parameters & Attributes

NameTypeDescription
optionsobjectStream configuration.

Return Value

PassThrough

An identity transform.

Working Example

Example Snippetnodejs
import { PassThrough } from 'node:stream';const p = new PassThrough();p.end('sample');let text = '';for await (const c of p)    text += c;console.log(text);
Node.js Reference