Open In App

Node url.toString() Method

Last Updated : 08 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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:




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


Output:

https://www.geeksforgeeks.org

Example 2:




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


Output:

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

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads