Readable stream
A Node.js stream you read data from, such as a file being read, an incoming HTTP request or a socket.
In more detail
It fills an internal buffer from its source and hands chunks to the consumer through data events, read() calls or for await loops. A custom one calls this.push(chunk) to add data and this.push(null) to signal the end.
Related terms
- stream — Data that flows between a program and a source or destination piece by piece, rather than all at once.
- flowing and paused modes — The two ways a Readable stream delivers data: in flowing mode it pushes chunks as fast as they arrive, in paused mode the consumer pulls them.
- async iteration — Looping over values that arrive over time with for await (const x of source), waiting for each one before the next turn of the loop.
- readable.push() — The method a custom Readable or Transform stream calls to add a chunk to its output buffer.
Taught in
- Stream Mechanics: Readable Streams & Flowing Modes — Node.js Internals & Backend Services
- Backpressure Engineering: Handling Mismatched I/O — Node.js Internals & Backend Services
- Stream Pipelines: pipeline, AbortSignal & Teardown — Node.js Internals & Backend Services