Finish an empty response
Health checks and acknowledgements that require no response body.
Express.js · Module
res.end() finishes an Express HTTP response, optionally writing a string or Buffer first. Use it for empty or low-level responses; use res.send() or res.json() for Express-managed response data.
res.end() finishes the current HTTP response, optionally writing a string or Buffer first. It is inherited from Node.js’s http.ServerResponse; use it for an empty or low-level response, and prefer res.send() or res.json() when Express should format response data.
res.end([data[, encoding]][, callback])| Name | Type | Description |
|---|---|---|
data | String | Buffer | undefined | String, Buffer, or undefined data to write before ending the response. |
encoding | String | undefined | Encoding used when data is a string. |
callback | Function | undefined | Function called once the response has finished. |
Response
res.end() when the response should finish without a body.res.end() as the usual data-response method; choose res.send() or res.json() when Express should handle the payload.const express = require('express');
const app = express();
app.get('/health', (req, res) => {
res.status(204).end();
});
app.listen(3000);Run this server, then request /health to receive an empty 204 response.
Health checks and acknowledgements that require no response body.
Sending a small raw payload when Express formatting is unnecessary.
Setting a status code while returning no body.
res.end() do in Express?res.end() terminates the response process and can optionally write a string or Buffer before termination. It is useful when no response body is needed.
Follow-up: How would you return an empty not-found response? Chain res.status(404).end().
res.end() receive?The method accepts optional data, an optional string encoding, and an optional completion callback. The data is written before the response is ended.
Follow-up: What data types are documented for the first argument? A string, Buffer, or undefined.
res.end() return, and how can it be chained?The method returns the Express Response object, allowing response methods to be chained. For example, res.status(404).end() sets the status before ending.
Follow-up: Why use res.send() or res.json() instead? They are the documented choices when the response should contain Express-managed data.
res.send()res.json()res.status()http.ServerResponse.response.end()