Writable stream
A Node.js stream you write data to, such as a file being written, an HTTP response or a socket.
In more detail
write(chunk) returns false once the internal buffer has reached highWaterMark, which means stop and wait for the drain event. end() says no more data will come, and finish fires when everything has been flushed.
Related terms
- stream — Data that flows between a program and a source or destination piece by piece, rather than all at once.
- highWaterMark — A stream option giving how much data its internal buffer should hold before it signals backpressure: bytes normally, or objects in object mode.
- drain event — The event a Writable stream emits when its buffer has emptied after write() returned false, meaning it is safe to write again.
- backpressure — A slow consumer signalling a fast producer to pause, so data does not pile up in memory faster than it can be handled.
Taught in
- Writable Streams: Drain Events & highWaterMark — 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