stream.Readable

A source you read data from chunk by chunk.

Since Node 0.x; Readable.from Node 12.3 Spec ↗

Syntax

Readable.from(iterable)  /  new Readable({ read() {} })

Returns

Readable — A readable stream, also async-iterable.

Examples

import { Readable } from 'node:stream';

const r = Readable.from(['a', 'b', 'c']);
for await (const chunk of r) {
  console.log(chunk);
}
Output
a
b
c
import { Readable } from 'node:stream';

let n = 0;
const counter = new Readable({
  read() {
    this.push(n < 3 ? String(n++) : null);
  },
});
counter.on('data', (c) => console.log(c.toString()));
Output
0
1
2

Notes

`Readable.from()` adapts any iterable or async generator into a stream. Async iteration is the simplest consumption API and handles backpressure automatically. Push `null` to signal end-of-stream.

See also