Express.js res.sendStatus() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Response

Definition

In Express.js, res.sendStatus(statusCode) sets the response status and sends the registered status message as a plain text body. Example: res.sendStatus(404) responds with status 404 and body Not Found.

Use it for short status-only replies (health checks, quick denies). For a custom message or JSON error, use res.status(code) with res.send() or res.json() instead.

Syntax

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

Express
res.sendStatus(statusCode)
CallWhat it does
res.sendStatus(statusCode)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.sendStatus(statusCode)

Parameters

ParameterDescription
statusCodeRequired. HTTP status to set. Its registered message becomes the text body. Unknown codes use the number as the body text.
200Required. OK
201Required. Created
403Required. Forbidden
404Required. Not Found
500Required. Internal Server Error

Return Value

res.sendStatus(code) sets the status, sends the default status text body, and ends the response. It returns res, but the cycle is already finished.

Express
return res.sendStatus(404);
// equivalent idea: res.status(404).send('Not Found')

Express.js Examples

Example 1 — Not Found with sendStatus(404)

Return the standard Not Found text when a resource is missing.

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

app.get('/item/:id', (req, res) => {
  const found = false; // demo: nothing in the store

  if (!found) {
    return res.sendStatus(404);
    // status 404, body: Not Found
  }

  res.json({ id: req.params.id });
});

app.listen(3000);

How It Works

  1. Check your condition. When the item is missing, exit early.
  2. Call sendStatus(404). Express sets the status and looks up the phrase.
  3. Body is the phrase. Clients receive the text Not Found.
  4. Response ends. No further res.json runs after the return.

Example 2 — Simple Health Check

Reply with 200 and the standard OK body.

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

app.get('/health', (req, res) => {
  res.sendStatus(200);
  // status 200, body: OK
});

app.listen(3000);

How It Works

  1. One-liner response. No custom payload is needed for a basic up check.
  2. 200 maps to OK. That text becomes the body automatically.
  3. Good for probes. Load balancers often only care that the status is success.
  4. JSON health? Use res.status(200).json({ status: 'up' }) instead.

Example 3 — When You Need a Custom Body

sendStatus cannot take a message argument. Chain status + send / json for custom content.

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

app.get('/secret', (req, res) => {
  // Wrong for custom text:
  // res.sendStatus(403); → body is always "Forbidden"

  res.status(403).json({ error: 'Admins only' });
});

app.listen(3000);

How It Works

  1. Know the limit. sendStatus only accepts the code — not a custom string.
  2. Set status first. res.status(403) prepares the status line.
  3. Send your payload. .json({…}) writes a structured error clients can parse.
  4. Express 5 tip. Old res.send(403) is gone — use sendStatus or status().send.

Runtime Support

res.sendStatus() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only receive the HTTP status and body.

✓ Server · Express 4 & 5

res.sendStatus()

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.sendStatus() 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 and sends the registered status message as a text body — for example 404 sends Not Found. Unknown codes send the number as the body.
res.sendStatus(code) always uses the standard reason phrase. res.status(code).send(body) lets you choose any custom body (string, JSON, and so on).
No. Express 5 removed res.send(statusNumber). Use res.sendStatus(404) instead, or quote a number if you truly mean to send digits as text.
No. sendStatus finishes the response. A second send causes headers-already-sent errors.
No. It runs on your Node.js server. Browsers only receive the status line and body over HTTP.

Next: res.set()

Set response headers before sending a body.

res.set() 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