Streams

stream/promises.pipeline()

Connects the stages and returns an awaitable completion result. On failure it tears down the connected streams; it is not a transaction that undoes bytes already written. Use a fresh pipeline for a new attempt and pass a signal for cancellation. Tested on Node.js 22.16.0. Example output (one line per entry): ["red blue"].

Formal Syntax & Structure

nodejs syntaxnodejs
pipeline(source[, ...transforms], destination[, options])

Parameters & Attributes

NameTypeDescription
sourceReadable | Iterable | AsyncIterable | FunctionInput stage.
transformsStream | FunctionZero or more conversion stages.
destinationWritable | FunctionFinal stage.
optionsobjectIncludes signal for cancellation.

Return Value

Promise

Resolves on completion or rejects on failure.

Working Example

Example Snippetnodejs
import { Readable, Writable } from 'node:stream';import { pipeline } from 'node:stream/promises';let text = '';await pipeline(Readable.from(['red', 'blue']), new Writable({ write(c, e, cb) { text += c + ' '; cb(); } }));console.log(text.trim());
Node.js Reference