Streams

Writable.write()

Queue a chunk and observe the boolean flow-control result. Local Node 22.16.0; production target compatibility pending. See https://nodejs.org/download/release/v22.16.0/docs/api/stream.html.

Formal Syntax & Structure

nodejs syntaxnodejs
writable.write(chunk[, encoding][, callback])

Parameters & Attributes

NameTypeDescription
chunkstring | Buffer | Uint8Array | objectData accepted by the configured stream.
encodingstringString encoding, when applicable.
callbackfunctionOptional write completion callback.

Return Value

boolean

Result or receiver of the documented operation; see the linked versioned API contract.

Working Example

Example Snippetnodejs
import { Readable, Writable, Transform } from 'node:stream';import { pipeline, finished } from 'node:stream/promises';import { once } from 'node:events';const sink = new Writable({highWaterMark:1,write(c,e,cb){setImmediate(cb);}});const accepted = sink.write('x');console.log(accepted);if(!accepted) await once(sink,'drain');sink.end(); await finished(sink,{cleanup:true});console.log('done');
Node.js Reference