Node | URL.origin API

url.origin is an inbuilt application programming interface(API) of the URL class within the url module.
url.origin API is used to gets the read-only serialization of the URL’s origin.

Syntax: url.origin
url : It is an object created by URL constructor.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

//Importing the url module
const url = require('url');
  
//Creating an URL_1 object with URL constructor.
const URL_1 = new URL("https://www.geeksforgeeks.org/geeks");
  
//Getting origin of above created URL_1 object
console.log(URL_1.origin);

chevron_right


Output:

https://www.geeksforgeeks.org

Note: We can not set the origin of URL using url.origin API. If we will try to do it then it will be ignored and origin will not be effected .

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

//Importing the url module
const url = require('url');
  
//Creating an URL_1 object with URL constructor.
const URL_1 = new URL("https://www.geeksforgeeks.org/geeks");
  
//Getting origin of above created URL_1 object
console.log(URL_1.origin);
  
//Setting URL_1 origin to https://www.geeks.com
URL_1.origin = "https://www.geeks.com";
  
//Getting origin after setting URL_1 origin
console.log(URL_1.origin);

chevron_right


Output:

https://www.geeksforgeeks.org


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.