res.status()

Sets the HTTP status code for the response and returns res for chaining.

Since Express 4 Spec ↗

Syntax

res.status(code)

Parameters

NameTypeRequiredDescription
code number Yes The HTTP status code, e.g. 200, 201, 404, 500.

Returns

Response — The response object, for chaining.

Examples

app.post('/users', (req, res) => {
  res.status(201).json({ id: 1 });
});
Output
(201 Created) {"id":1}
app.get('/missing', (req, res) => {
  res.status(404).send('Not Found');
});
Output
(404) Not Found

Notes

`status()` only sets the code - you must still call a terminal method (`send`, `json`, `end`) to deliver the response. Use `res.sendStatus(code)` to set the code and send the standard status text in one call.

See also