Express.js res.status() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Response

Definition

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(…).

It does not send the body by itself. Finish with res.send(), res.json(), res.end(), res.sendFile(), or another response method.

Syntax

Call res.status in your Express.js app. Start with this line.

Express
res.status(code)
CallWhat it does
res.status(code)Primary signature.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

res.status(code)

Parameters

ParameterDescription
codeRequired. HTTP status for the response (typically 100–599). Does not send a body.
200Required. OK — successful GET or update with a body
201Required. Created — new resource after POST
204Required. No Content — success with empty body (.end())
400Required. Bad Request — invalid client input
404Required. Not Found — missing resource
500Required. Internal Server Error — unexpected failure

Return Value

res.status(code) sets Node’s res.statusCode and returns res for chaining. It does not send a body by itself.

Express
return res.status(404).send('Not found');
return res.status(201).json({ id: 1 });

Express.js Examples

Example 1 — Created Resource with JSON

Set 201, then send the new object as JSON.

Express
const express = require('express');
const app = express();
app.use(express.json());

app.post('/users', (req, res) => {
  const user = { id: 101, name: req.body.name };
  res.status(201).json(user);
});

app.listen(3000);

How It Works

  1. Build the result. user is the new resource to return.
  2. Set status first. 201 means Created.
  3. Send JSON. .json(user) writes the body and finishes the response.
  4. 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);

How It Works

  1. Check the lookup. When nothing matches, take the error path.
  2. Set 404. Clients know the resource is missing.
  3. Send a clear message. Custom text beats a bare status for humans.
  4. 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).

Express
const express = require('express');
const app = express();

app.delete('/sessions/current', (req, res) => {
  // delete the session...
  res.status(204).end();
});

app.listen(3000);

How It Works

  1. Pick 204. Success with no payload to return.
  2. Call end(). Closes the response without writing a body.
  3. Avoid sendStatus(204). That would still send a reason-phrase body.
  4. Same idea as docs. Express shows res.status(403).end() for empty replies.

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.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via 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.

Next: res.type()

Set Content-Type from a MIME type or file extension.

res.type() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful