res.status()
Sets the HTTP status code for the response and returns res for chaining.
Syntax
res.status(code) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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.