HTTP

response.end()

Ends the message body, optionally writing a final piece of data. Every ordinary response path must eventually finish or deliberately terminate the connection. Completion of end does not confirm application-level processing by the remote client. Tested on Node.js 22.16.0. Example output (one line per entry): ["part-two"].

Formal Syntax & Structure

nodejs syntaxnodejs
response.end([data[, encoding]][, callback])

Parameters & Attributes

NameTypeDescription
datastring | Buffer | Uint8ArrayOptional final body data.
encodingstringEncoding of string data.
callbackFunctionCompletion callback.

Return Value

http.ServerResponse

The response instance.

Working Example

Example Snippetnodejs
import http from 'node:http';const server = http.createServer((req, res) => { res.write('part-'); res.end('two'); });await new Promise(r => server.listen(0, '127.0.0.1', r));const url = 'http://127.0.0.1:' + server.address().port;try {    console.log(await (await fetch(url)).text());}finally {    server.closeAllConnections();    await new Promise(r => server.close(r));}
Node.js Reference