- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
urlObject.auth() Method in Node.js
The auth() property defines the username and password portion of any URL, also called as userInfo. The string and username are separated by a colon ( : ).
Syntax
urlOject.auth()
Parameters
Since it retuns only the username and password from a URL, it does not required any input parameters.
Example
Create a file with name – auth.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −
node auth.js
auth.js
// Importing the URL module const url = require('url'); var adr = 'https://username=hello:password=tutorialspoint@www.tutorialspoint.com/'; // Parsing the above URL address var q = url.parse(adr, true); // Printing the auth details console.log(q.auth);
Output
C:\home
ode>> node auth.js username=hello:password=tutorialspoint
Example
Let's take a look at one more example.
// Importing the URL module const url = require('url'); var adr = 'http://username=admin:password=tutorialspoint123@www.tutorialspoint.com/'; // Parsing the above URL address var q = url.parse(adr, true); // Printing the auth details console.log(q.auth);
Output
C:\home
ode>> node auth.js username=admin:password=tutorialspoint123
Advertisements