Skip to content
Related Articles

Related Articles

Node.js urlObject.href API

View Discussion
Improve Article
Save Article
  • Last Updated : 14 Oct, 2021

The urlObject.href API is used to return the complete URL string along with the protocols(HTTP) and pathname or other search terms.


For example: ''

Here, Protocol = http
      Path = /login
      Host = 'www'
      File Name = password.html

Below programs illustrates the use of urlObejct.href method in Node.js:

Example 1:

// Node program to demonstrate the 
// urlObject.href API as Setter
// It will return a URL object
const gfg = new URL(' '); 
// Output the fetched url


Example 2:

// Node program to demonstrate the  
// url.href API as Setter
// Importing the module 'url-parse'
// Use command 'npm install url-parse' in command
// prompt to import this module
var parse = require('url-parse'); 


Note: The above program will compile and run by using the node app.js command.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!