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)

filter_none

edit
close

play_arrow

link
brightness_4
code

//Creating an URL_1 object with URL constructor.
  
//Getting username of above created URL_1 object
console.log(URL_1.username);

chevron_right


Output:

ashish

Example 2: (Setting the username of URL)

filter_none

edit
close

play_arrow

link
brightness_4
code

//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


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


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 :

1


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