Node | URL.username API
URL.username is an inbuilt application programming interface(API) of the URL class within the Node.JS.
URL.username API is used to get and set the username of URL.
Syntax: url.username url : It is an object created by URL constructor.
Example 1: (Getting the username of URL)
//Creating an URL_1 object with URL constructor. //Getting username of above created URL_1 object console.log(URL_1.username); |
chevron_right
filter_none
Output:
ashish
Example 2: (Setting the username of URL)
//Creating an URL_1 object with URL constructor. //Getting username of above created URL_1 object console.log("Before changing username URL is:") console.log(URL_1.href); console.log("username: "+ URL_1.username); //Setting URL_1 username to ashu URL_1.username = "ashu"; //Getting username after setting it to ashu console.log("After changing username URL is:") console.log(URL_1.href); console.log("username: "+ URL_1.username); |
chevron_right
filter_none
Output:
Before changing username URL is: https://ashish:ashish123@www.geeksforgeeks.org/geeks username: ashish After changing username URL is: https://ashu:ashish123@www.geeksforgeeks.org/geeks username: ashu
Recommended Posts:
- Why Node.js ?
- Node js | OS
- Node | URL.password API
- Promises in Node.js
- Node | URL.pathToFileURL API
- Node | URL.fileURLToPath API
- Node | URLSearchParams.set()
- Node | URL.resolve(from,to) API
- Node | URL.search API
- Node | URL.port API
- Routing in Node.js
- Node | URL.origin API
- Node | URL.host API
- Node | URL.hostname API
- Node | URL.format 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.



