The url.protocol is an inbuilt application programming interface of class URL within URL module which is used to get and set the protocol scheme of the URL.
Return value: It get and set protocol scheme of the URL
Example 1: This example changes the special protocols to hypothetical protocols like http->https.
Before Change http://gfg.org/foo After Change https://gfg.org/foo
Example 2: This example try changes the non-special protocol to a special protocol like smtp->http but it will not change.
Before Change smtp://gfg.org/foo After Change smtp://gfg.org/foo
Example 3: This example try to change the special protocols to hypothetical protocols like ftp->fish but it will not change.
Before Change ftp://gfg.org/foo After Change ftp://gfg.org/foo
Example 4: This example try to change from non-special protocols to hypothetical protocols like ssh->fish.
Before Change ssh://gfg.org/foo After Change fish://gfg.org/foo
Example 5: It can be used as a getter.
- Different types of Coding Schemes to represent data
- Node.js | NPM (Node Package Manager)
- Node js | OS
- PHP vs. Node.js
- Why Node.js ?
- Routing in Node.js
- Node | URL.domainToASCII
- Node | URLSearchParams.get()
- Node | URL.resolve(from,to) API
- Node | URLSearchParams.has()
- HTTPS in Node
- Node | URL.fileURLToPath API
- Promises in Node.js
- Node | URL.pathToFileURL API
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.