The res.end() function concludes the response process and is derived from the HTTP.ServerResponse's response.end() method in the Node core. It is used to end the response, with or without data.

Syntax:
res.end([data[, encoding]][, callback])Parameters:
- data: The optional data to write before ending the response.
- encoding: The encoding used when data is a string.
- callback: An optional function called when the response has finished.
Return Value: Returns the response object (res).
Installation of the express module:
You can visit the link to Install the express module. You can install this package by using this command.
npm install expressAfter installing the express module, you can check your express version in the command prompt using the command.
npm version expressAfter that, you can just create a folder and add a file, for example, index.js. To run this file you need to run the following command.
node index.jsProject Structure:

Example 1: Below is the code example of the res.end() Method:
const express = require('express');
const app = express();
const PORT = 3000;
// Without middleware
app.get('/',
function (req, res) {
res.end();
});
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:

Example 2: Below is the code example of the res.end() Method:
const express = require('express');
const app = express();
const PORT = 3000;
app.use('/user', function (req, res, next) {
console.log("/user called");
res.end();
});
app.get('/user', function (req, res) {
console.log("User Page");
res.end();
});
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: go to http://localhost:3000/user, then you will see the following output on your console

Working of res.end()
- An Express application receives a client request.
- The route handler or middleware gets access to the response object through res.
- res.end() signals that the response is complete.
- Any optional response data is written before the response is ended.
- After the response is ended, no additional response data should be sent.
Use Cases of res.end()
- Ending an HTTP response without sending a response body.
- Completing a response after writing data manually.
- Ending responses inside middleware or route handlers.
- Handling requests where no response content is required.
- Explicitly terminating the response when the server has finished sending data.