Express JS req.hostname Property Last Updated : 15 Jul, 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.protocol Property G gouravhammad Follow Improve Article Tags : Web Tech Similar Reads 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 Express.js req.protocol Property The req.protocol property contains the request protocol string which is either HTTP or (for TLS requests) https. When the trust proxy setting does not evaluate to false, this property will use the X-Forwarded-Proto header field value if it is present. Syntax: req.protocol Parameter: No parameters. 2 min read Express req.query Property The req.query property in Express allows you to access the query parameters from the URL of an incoming HTTP request. Query parameters are typically key-value pairs that are appended to the URL after the "?" symbol, and they are separated by the "&" symbol.Syntax:req.queryParameter: req.query do 2 min read Express.js app.locals Property In Express.js, app.locals is an object used to store variables that need to be available throughout the app. These variables can be accessed globally across different routes or middleware and are often used for configuration settings or values that should be sharedWhat is app.locals?app.locals is an 3 min read Express.js res.location() Function The res.location() function is used to set the response Location HTTP header to the path parameter which is being specified. Basically, it is used to set the response header. It doesn't end the response, after using it you can write a response body if you want to write. Syntax: res.location( path ) 2 min read HTTP Request and Response Cycle in Express.js The HTTP request and response cycle is the backbone of secure communication on the web. In Express.js, req (request) and res (response) objects are fundamental to handling HTTP requests and sending back responses. They are passed as arguments to route handlers and middleware functions. In this artic 5 min read Like