Streams

writable.writableNeedDrain

Reports whether the write queue has crossed its flow-control threshold and a drain notification is expected. Use it for observation; the write return value and proper event handling remain the normal producer contract. Tested on Node.js 22.16.0. Example output (one line per entry): ["true", "false"].

Formal Syntax & Structure

nodejs syntaxnodejs
writable.writableNeedDrain

Return Value

boolean

Whether drain is expected.

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); } });w.write('x');console.log(w.writableNeedDrain);await once(w, 'drain');console.log(w.writableNeedDrain);w.end();await finished(w, { cleanup: true });
Node.js Reference