Express JS req.hostname Property Last Updated : 08 Jan, 2025 Comments Improve Suggest changes Like Article Like Report In the world of web development the use of Node.Js, Express.Js stands out as a strong and popular framework for building internet packages and APIs. Within Express.Js, the req.hostname property serves as a beneficial tool for retrieving the hostname distinctive in the HTTP request made to the server. These belongings give insights into the domain name used to access the server, providing builders with essential information about incoming requestsPrerequisitesNode JSExpress JS HTTP protocolThe req.hostname property contains the hostname which is derived from the Host HTTP header. It basically returns the hostname which is being supplied in the host HTTP header. Syntax: req.hostnameParameter: No parameterReturn Value: StringSetup project and installing modulesStep 1: You can install this package by using this command. npm init - ynpm install expressProject Structure:The updated dependencies in package.json file will look like:"dependencies": { "express": "^4.18.2"}Example 1: Write the following code in index.js file. javascript //index.js const express = require("express"); const app = express(); const PORT = 3000; app.get("/", function (req, res) { console.log(req.hostname); res.send(); }); 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:Suppose we have a domain name instead of localhost as shown below: Host: "demo.com:3000"console.log(req.hostname);Console output: demo.comReference: https://expressjs.com/en/4x/api.html#req.hostname Comment More infoAdvertise with us Next Article Express JS req.hostname Property G gouravhammad Follow Improve Article Tags : JavaScript Web Technologies Node.js Express.js Similar Reads Express.js req.ips Property The req.ips property contains an array of IP addresses specified in the X-Forwarded-For request header. It returns an array of IP addresses. Syntax: req.ips Parameter: No parameter. Return Value: Array Installation of the express module: You can visit the link to Install the express module. You ca 2 min read Express.js req.ip Property The req.ip property contains the remote IP address of the request. It is useful when the user wants the IP address of the incoming request made to the application. Syntax:req.ipParameter: No parameter. Return Value: String Installation of the express module:You can visit the link to Install the expr 2 min read Express req.params Property The req.params property is an object containing properties mapped to the named route âparametersâ. For example, if you have the route /student/:id, then the âidâ property is available as req.params.id. This object defaults to {}. Syntax:req.paramsParameter: No parameters. Return Value: Object The re 2 min read Express.js req.app Property The req.app property holds the reference to the instance of the Express application that is using the middleware. Syntax: req.app Parameter: No parameters. Return Value: Object Installation of the express module: You can visit the link to Install the express module. You can install this package b 2 min read Express res.locals Property The `res.locals` property is an object that holds response local variables specific to the current request. It has a scope limited to the request and is accessible only to the view(s) rendered during that particular request/response cycle, if any. Syntax:res.localsParameter: No parameters. Return Va 2 min read Like