Node | urlObject.href API
The urlObject.href API is used to return the complete URL string along with the protocols(HTTP) and pathname or other search terms.
Syntax
urlObject.href
For example: 'http://www.geeksforgeeks.com/login/password.html'
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 // Output the fetched url console.log(gfg.href); |
chevron_right
filter_none
Output:
https://www.geeksforgeeks.com/login.html
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'); console.log(url.href); |
chevron_right
filter_none
Output:
https://www.example.com:777/a/b?c=d&e=f#g
Note: The above program will compile and run by using the node app.js command.
Reference: https://nodejs.org/api/url.html#url_urlobject_href
Recommended Posts:
- Node.js | NPM (Node Package Manager)
- PHP vs. Node.js
- Why Node.js ?
- Node js | OS
- Node | URLSearchParams.get()
- Node | URL.domainToUnicode
- Node | URL.domainToASCII
- Node.js Events
- Node | URL.pathToFileURL API
- Node | URL.host API
- Node | URLSearchParams.set()
- Node | URL.hash API
- Node.js | pop() function
- Node | URL.pathname API
- Node | URL.protocol API
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

