Streams

readable.push()

Adds data to a custom readable source; null marks end of input. A false result signals that the producer should stop adding data until requested again. Implement this in a source rather than using push to feed arbitrary consumer streams. Tested on Node.js 22.16.0. Example output (one line per entry): ["ink"].

Formal Syntax & Structure

nodejs syntaxnodejs
readable.push(chunk[, encoding])

Parameters & Attributes

NameTypeDescription
chunkanyData or null at EOF.
encodingstringEncoding for string chunks.

Return Value

boolean

Whether the producer may continue filling the queue.

Working Example

Example Snippetnodejs
import { Readable } from 'node:stream';let sent = false;const r = new Readable({ read() { if (!sent) {        sent = true;        this.push('ink');        this.push(null);    } } });let text = '';for await (const part of r)    text += part;console.log(text);
Node.js Reference