Horje
Node.js urlObject.host API

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://horje.org/practice
horje.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.




//Importing the url module
const url=require('url');
  
//creating a new url object
var link = new URL("https://google.com/coding_challenges");
  
//Using the .host() function to print the host name in the url
console.log(link.host);

OUTPUT:
google.com


Reffered: https://www.geeksforgeeks.org


Node.js

Related
Node.js URL.format(urlObject) API Node.js URL.format(urlObject) API
Node.js URL.format API Node.js URL.format API
Sequential Functionality in Node.js Sequential Functionality in Node.js
Node.js urlObject.search API Node.js urlObject.search API
Node.js urlObject.protocol API Node.js urlObject.protocol API

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
8