Node | url.toString() Method

The url.toString() method is an inbuilt application programming interface(API) of the URL module within the Node.JS. The url.toString() method is used to return the serialized URL. The returned value is equivalent to that of url.href and url.toJSON().

Syntax:

url.toString()

Parameters: This method accepts single parameter as mentioned above and described below:

  • url: It is an object created by URL constructor.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Creating an URL object with URL constructor. 
const url = new URL("https://www.geeksforgeeks.org"); 
  
// Using toString() method 
console.log(url.toString()); 

chevron_right


Output:



https://www.geeksforgeeks.org

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Creating an URL object with URL constructor. 
const url = new URL("https://www.google.com?foo=bar"); 
  
// Using toString() method 
console.log(url.toString()); 

chevron_right


Output:

https://www.google.com/?foo=bar

Reference: https://nodejs.org/api/url.html#url_url_tostring

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.