Skip to content
Related Articles

Related Articles

Node.js API

Improve Article
Save Article
Like Article
  • Last Updated : 14 Oct, 2021

The utilities for URL resolution and parsing is provided by the URL module.
A URL string is a structured string that contains various multiple meaningful components. When parsed, a URL object is returned that contains properties for each of these components. return the host name in the url as a string.

localhost:8080 - is the host name. - is the host name.

In the below example we first create a URL object. Then after using the .host() function, we will get the hostname in the URL as output.

//Importing the url module
const url=require('url');
//creating a new url object
//Using the .host() function to print the host name in the url
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!