Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Function

res.status

res.status(code) sets an Express response’s HTTP status code and returns the response object for chaining. Use it before methods that send or finish the response.

How it works

Call res.status(code) to assign the HTTP status for the response. Because it returns the Response object, chain it with methods such as json(), send(), end(), or sendFile() to complete the response.

Syntax

res.status(code)

Parameters

NameTypeDescription
codeNumberThe numeric HTTP status code to set on the response.

Returns

Response

Key points

  • The method assigns the HTTP status code that Express will use for the outgoing response.
  • The returned Response object enables fluent response construction.
  • Call end() after setting a status when no response body is needed.
  • Combine a status with send() to return a body in the same operation.
  • The status can also precede sendFile() when returning a file response.

Common mistakes

  • Pass a numeric HTTP status code; this method is not the replacement for sending a status-only response body.
  • The method changes the response status code but does not itself send or finish the response; chain a terminating response method.

Example: Set a response status before sending JSON

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

app.get('/health', (req, res) => {
  res.status(200).json({ ok: true });
});

app.listen(3000);

Run this Express app and request /health to receive a JSON response with HTTP status 200.

When to use it

Send a status with text or JSON

An endpoint must report a client or server outcome while returning a body.

Set a status and end the response

A handler must finish without returning content.

Set a status before sending a file

A route returns a file but needs a non-default status.

Interview questions

QWhat does res.status() do, and what does it return?

res.status(code) sets the HTTP status code and returns the Response object. Its chainable return makes patterns such as res.status(400).send('Bad Request') possible.

Follow-up: How would you send only a status and its standard text? Use res.sendStatus(code), which sets the status and sends the registered status message.

QWhat argument does res.status() accept?

The argument is code, a Number representing the HTTP status code for the response. The method is a chainable alias of Node’s response.statusCode.

Follow-up: What should follow res.status() when the request must be completed? Chain a method such as end(), send(), json(), or sendFile().

QHow should status and a JSON body be sent together?

Use res.status() separately before sending a body, for example res.status(500).json({ error: 'message' }). This is the documented replacement for deprecated status arguments on older response-method signatures.

Follow-up: Why avoid res.json(body, status) in modern Express code? Its positional status form is deprecated; set the status separately and chain the response method.

  • res.send()
  • res.json()
  • res.end()
  • res.sendFile()
  • res.sendStatus()
  • response.statusCode

Source: Response - Express.js 4.x. Checked 2026-10-15.