Node | urlObject.protocol API
With the help of urlObject.protocol() method, we can find the name of protocol which is used by the given hostname.
Syntax :
urlObject.protocol()
Return : Returns the protocol used (i.e. – http, https, ftp, etc.)
Example #1 : In this example, with the help of urlObject.protocol() method we are able to extract the protocol used from the hostname.
// Importing the module 'url' const url = require('url'); var adr = // Parse the address: var q = url.parse(adr, true); /* The parse method returns an object containing URL properties */ console.log(q.protocol); |
chevron_right
filter_none
Output :
http:
Example #2 :
// Importing the module 'url' const url = require('url'); var adr = // Parse the address: var q = url.parse(adr, true); /* The parse method returns an object containing URL properties */ console.log(q.protocol); |
chevron_right
filter_none
Output :
https:
Recommended Posts:
- Node js | OS
- Why Node.js ?
- Node | URL.port API
- Node | URLSearchParams.has()
- Node.js Events
- Promises in Node.js
- Routing in Node.js
- Node | URL.pathToFileURL API
- Node | URL.host API
- Node | URL.fileURLToPath API
- Node | URL.format API
- Node | URL.pathname API
- Node | URL.search API
- Node | URLSearchParams.get()
- Node | URL.resolve(from,to) 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 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.



