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
| Name | Type | Description |
|---|---|---|
| source | Readable | Iterable | AsyncIterable | Function | Input stage. |
| transforms | Stream | Function | Zero or more conversion stages. |
| destination | Writable | Function | Final stage. |
| options | object | Includes 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());