res.sendStatus()
Sets the status code and sends its standard status message as the body.
Syntax
res.sendStatus(statusCode) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
statusCode | number | Yes | The HTTP status code to set and send. |
Returns
Response — The response object.
Examples
app.delete('/items/:id', (req, res) => {
remove(req.params.id);
res.sendStatus(204);
});
Output
(204 No Content)
app.post('/login', (req, res) => {
res.sendStatus(401);
});
Output
(401) Unauthorized
Notes
Sends the textual reason phrase as the body (e.g. body `"Not Found"`
for 404). For an empty body with a specific code use
`res.status(code).end()`; for a JSON error use
`res.status(code).json(...)`.