Node | urlObject.pathname API

With the help of urlObject.pathname() method, we can find the name of the path which is used by the given hostname. This contains all the things starting from the host (with the port) and before the beginning of the query or hash components, which are delimited by one of the ASCII question mark (?) or hash (#) characters.

Syntax: urlObject.pathname()
Return: Returns the pathname used(i.e.'/p/a/t/h')

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:



/a/b

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

/

Supported Browsers:

  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari


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.