Streams

writable.write()

Queues output and reports whether further writes should continue immediately. False is not a failed write: wait for drain before producing more. The completion callback is separate from the boolean flow-control result. Tested on Node.js 22.16.0. Example output (one line per entry): ["false", "done"].

Formal Syntax & Structure

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

Parameters & Attributes

NameTypeDescription
chunkanyValue accepted by this writable.
encodingstringEncoding for strings.
callbackFunctionCalled after handling this chunk.

Return Value

boolean

Whether it is appropriate to continue writing.

Working Example

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