Node.js urlObject.hostname API
The url.hostname is an inbuilt application programming interface of class URL within the url module which is used to get and set the hostname portion of the URL. The url.hostname does not include the port number.
Syntax:
url.hostname
It associates by single value url which is an object created by URL constructor.
Example:
const { URL } = require( 'url' );
console.log( "Before Change" );
console.log(myURL.hostname);
console.log( '' );
myURL.hostname = 'example2.com' ;
console.log( "After Change" );
console.log(myURL.hostname);
|
Output:
Before Change
gfg.org
After Change
geeksforgeeks.org
Reference: https://nodejs.org/dist/latest-v10.x/docs/api/url.html#url_url_hostname
Last Updated :
14 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...