Streams
writable.end()
Indicates that no more data will be written, optionally with one final chunk. Await completion when the result matters. This is not a guarantee of persistence to disk or receipt by a remote application. Tested on Node.js 22.16.0. Example output (one line per entry): ["one two true"].
Formal Syntax & Structure
nodejs syntaxnodejs
writable.end([chunk[, encoding]][, callback])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| chunk | any | Optional final data. |
| encoding | string | Encoding for final string. |
| callback | Function | Completion callback. |
Return Value
Writable
The writable instance.
Working Example
Example Snippetnodejs
import { Writable } from 'node:stream';import { finished } from 'node:stream/promises';let body = '';const w = new Writable({ write(c, e, cb) { body += c; cb(); } });w.write('one ');w.end('two');await finished(w, { cleanup: true });console.log(body, w.writableFinished);