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

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 expressStep 2: After installing the express module, you can check your express version using the command:
npm version expressStep 3: Create an index.js file and run the following command.
node index.jsProject Structure:

Example: Below is the code example of the res.status() Method:
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.jsOutput:
Server listening on PORT 3000Browser output: go to http://localhost:3000/user, you will see the following output:

Example 2: Below is the code example of the res.status() Method:
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.jsConsole 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:

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.