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

NameTypeDescription
chunkanyOptional final data.
encodingstringEncoding for final string.
callbackFunctionCompletion 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);
Node.js Reference