The 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.
Paramter: No parameter
Return Value: String
Installation of express module:
- You can visit the link to Install express module. You can install this package by using this command.
npm install express
- After installing the express module, you can check your express version in command prompt using the command.
npm version express
- After 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.
Example 1: Filename: index.js
Steps to run the program:
- The project structure will look like this:
- Make sure you have installed express module using the following command:
npm install express
- Run index.js file using below command:
Server listening on PORT 3000
- Now open your browser and go to http://localhost:3000/, now you can see the following output on your console:
Server listening on PORT 3000 localhost
Example 2: Suppose we have a domain name instead of localhost as shown below:
Host: "demo.com:3000" console.log(req.hostname);
- Scaffolding an ExpressJS app from scratch
- Routing Path for ExpressJS
- HandleBars Templating in ExpressJS
- CSS | transition-property Property
- HTML | DOM lang Property
- HTML | DOM Style backgroundClip Property
- HTML | DOM Style borderTop Property
- HTML | DOM Meter max Property
- HTML | DOM Input Hidden value Property
- CSS | table-layout Property
- CSS | text-align Property
- CSS | border-top-width Property
- Web Window API | Window locationbar property
- HTML | DOM Textarea autofocus Property
- HTML | DOM Style columnGap Property
- HTML | DOM Input Time autofocus Property
- HTML | DOM Input Submit formTarget Property
- HTML | DOM Style boxSizing Property
- HTML | DOM Video seekable Property
- HTML | DOM Input Checkbox disabled Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.