Streams

readable.pipe()

Connects readable output to a writable destination and coordinates flow control. The destination normally ends when the source ends. A pipeline is usually a better choice when multiple stages need coordinated error handling and destruction. Tested on Node.js 22.16.0. Example output (one line per entry): ["ab"].

Formal Syntax & Structure

nodejs syntaxnodejs
readable.pipe(destination[, options])

Parameters & Attributes

NameTypeDescription
destinationWritableTarget stream.
optionsobjectSet end to false to retain destination ownership.

Return Value

Writable

The destination, enabling chaining.

Working Example

Example Snippetnodejs
import { Readable, Writable } from 'node:stream';import { finished } from 'node:stream/promises';let text = '';const w = new Writable({ write(c, e, cb) { text += c; cb(); } });Readable.from(['a', 'b']).pipe(w);await finished(w, { cleanup: true });console.log(text);
Node.js Reference