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.
const url = require( 'url' );
var adr =
var q = url.parse(adr, true );
console.log(q.protocol);
|
Output :

Example #2 :
const url = require( 'url' );
var adr =
var q = url.parse(adr, true );
console.log(q.protocol);
|
Output :
