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
| Name | Type | Description |
|---|---|---|
| chunk | any | Value accepted by this writable. |
| encoding | string | Encoding for strings. |
| callback | Function | Called 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');