Node.js urlObject.host API
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.
url.host() return the host name in the url as a string.
Examples:
http://localhost:8080/register
localhost:8080 - is the host name.
https://geeksforgeeks.org/practice
geeksforgeeks.org - 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.
const url=require( 'url' );
console.log(link.host);
|
OUTPUT:
google.com
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...