readable.pipe()

Connects a readable stream to a writable stream, managing backpressure.

Since Node 0.x Spec ↗

Syntax

readable.pipe(destination[, options])

Parameters

NameTypeRequiredDescription
destination Writable Yes The writable stream to write data into.
options object No `{ end: false }` keeps the destination open after the source ends.

Returns

Writable — The destination stream, allowing chained pipes.

Examples

import { createReadStream, createWriteStream } from 'node:fs';

createReadStream('in.txt').pipe(createWriteStream('out.txt'));
import { createServer } from 'node:http';
import { createReadStream } from 'node:fs';

createServer((req, res) => {
  const s = createReadStream('./page.html');
  s.on('error', () => { res.statusCode = 404; res.end(); });
  s.pipe(res);
}).listen(3000);

Notes

`pipe` handles backpressure automatically but does NOT forward errors: an error on the source leaves the destination open and may leak resources. For production use `stream.pipeline` instead.

See also