In Express.js, res.status(code) sets the HTTP status code for the outgoing reply. It is a chainable alias of Node.js response.statusCode and returns res, so you typically write res.status(404).send(…) or res.status(201).json(…).
Build the result.user is the new resource to return.
Set status first.201 means Created.
Send JSON..json(user) writes the body and finishes the response.
One chain.status returns res, so .json runs on the same object.
Example 2 — Not Found with a Message
Early return with 404 and a plain text body (official style: status + send).
Express
const express = require('express');
const app = express();
app.get('/users/:id', (req, res) => {
const found = false; // look up the user in a real app
if (!found) {
return res.status(404).send('User not found');
}
res.send('User found');
});
app.listen(3000);
Output
GET /users/99
Status: 404
Body: User not found
How It Works
Check the lookup. When nothing matches, take the error path.
Set 404. Clients know the resource is missing.
Send a clear message. Custom text beats a bare status for humans.
Return early. Stops the handler from calling res.send again.
Example 3 — No Content with end()
Official pattern: res.status(code).end() when there is no body (here 204).
Call end(). Closes the response without writing a body.
Avoid sendStatus(204). That would still send a reason-phrase body.
Same idea as docs. Express shows res.status(403).end() for empty replies.
Compatibility
Runtime Support
res.status() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only receive the status on the HTTP response.
✓ Server · Express 4 & 5
res.status()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
res.status()Express on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.
Frequently Asked Questions
It sets the HTTP status code for the response. It is a chainable alias of Node’s response.statusCode and returns res so you can call send, json, end, or sendFile next.
No. It only sets the status. You must still call res.send(), res.json(), res.end(), res.sendFile(), or a similar method.
res.status(code) lets you choose any body. res.sendStatus(code) sets the status and sends the standard reason phrase as text in one step.
Use 201 Created when a POST (or similar) successfully creates a resource, then send the new data with .json() or .send().
No. It runs on your Node.js server. Browsers only see the status line on the HTTP response.