Express res.status() Function

Last Updated : 26 Aug, 2026

The res.status() function is used to set the HTTP status code for the response before sending it to the client. It returns the response object (res), allowing it to be chained with methods such as res.send() and res.json().

frame_3270-

Syntax:

res.status( code )

Parameter: This function accepts a single parameter code that holds the HTTP status code. 

Return Value: Returns the response object (res), allowing method chaining.

Steps to create the Express App and Installing the Modules:

Step 1: You can install this package by using this command.

npm install express

Step 2: After installing the express module, you can check your express version using the command:

npm version express

Step 3: Create an index.js file and run the following command.

node index.js

Project Structure:

NodeProj

Example: Below is the code example of the res.status() Method:

JavaScript
const express = require('express');
const app = express();
const PORT = 3000;
// Without middleware
app.get('/user', function (req, res) {
    res.status(200).send("User Page");
})
app.listen(PORT, function (err) {
    if (err) console.log(err);
    console.log("Server listening on PORT", PORT);
});

Steps to run the program:

node index.js

Output:

Server listening on PORT 3000

Browser output: go to http://localhost:3000/user, you will see the following output:

Screenshot-2026-08-07-162929

Example 2: Below is the code example of the res.status() Method:

JavaScript
const express = require("express");
const app = express();
const PORT = 3000;
app.get("/success", (req, res) => {
    res.status(200).send("Request Successful");
});
app.listen(PORT, () => {
    console.log(`Server listening on PORT ${PORT}`);
});

Steps to run the program:

node index.js

Console Output: go to http://localhost:3000/, now check your console and you will see the following output:

Server listening on PORT 3000

Browser Output: And you will see the following output on your browser screen:

Screenshot-2026-08-07-164328

Working of res.status()

  • The client sends an HTTP request.
  • Express executes the matching route handler.
  • res.status() sets the HTTP status code for the response. The response is sent using methods such as res.send() or res.json().
  • The client receives the response along with the specified HTTP status code.

We have a complete list of Express Response methods, properties and events, to check those please go through this Express Response Complete Reference article.

Comment