Open In App
Related Articles

Node.js urlObject.auth API

Improve Article
Improve
Save Article
Save
Like Article
Like

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

Syntax :

urlObject.auth()  

Return: Returns the string of authentication parameters. 

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

javascript




// importing the module 'url'
const url = require('url');
 
const adr =
 
// Parse the address:
const q = url.parse(adr, true);
 
/* The parse method returns an object containing
 URL properties */
console.log(q.auth);


Output: 


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

javascript




// importing the module 'url'
const url = require('url');
 
const adr =
 
// Parse the address:
const q = url.parse(adr, true);
 
/* The parse method returns an object containing
 URL properties */
console.log(q.search);


Output: 

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 31 Mar, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials