Node | urlObject.auth API

With the help of urlObject.auth() method, we can find the authentication parameter within the hostname. This method return the string of parameters.

Syntax : urlObject.auth()
Return : Returns the string of authentication parameter.

Example #1 : In this example with the help of urlObject.auth() method we are able to extract the username and password from the hostname.

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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.auth);

chevron_right


Output :

username=jitender:password=geeks

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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.search);

chevron_right


Output :

username=author:password=truegeek


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.