| Node.js URL.origin API
Node.js URL.origin API
When we say about the url.origin, it is an inbuilt application programming interface of the URL class within the url module. And url.origin API is mainly used to gets the read only serialization of the URL's origin.
And syntax of url.origin is given below:-
Syntax: url.origin
url: It is an object created by URL constructor.
But you need to import the URL module in Node.js by using the below command.
npm install URL
And the below is an example of using url.origin and file name is ExampleURLOrigin.js.
To get the code click hereDownload Code
And to run the above file we use the Node.js command prompt and run the below command.
Node ExampleURLOrigin.js
And output of above command is given below:-
And we will take one more example we can set the origin of URL using url.origin API. And if we try to do it then it will be ignored and origin will not be effected. We name the file as ExampleURLOrigin2.js.
To get the code click hereDownload Code
And to run the above file we use the Node.js command prompt and run the below command.
Node ExampleURLOrigin2.js
And output of above command is given below:-
| | |