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
- Special variables in Perl
- Node.js | NPM (Node Package Manager)
- Node.js | os.EOL
- Node js | OS
- PHP vs. Node.js
- Why Node.js ?
- Node | URL.format API
- Node | URL.resolve(from,to) API
- Node | URL.domainToASCII
- Node.js | First Application
- Node | URLSearchParams.get()
- Node | URL.domainToUnicode
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.