Skip to content
Related Articles

Related Articles

Node | urlObject.href API
  • Last Updated : 17 Jul, 2019

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.


Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :