Open In App
Related Articles

Node.js URL.origin API

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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: 
 

javascript

//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);

                    

Output: 
 


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

javascript

//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);

                    

Output: 
 


 



Last Updated : 14 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads