Skip to content
Related Articles

Related Articles

Node.js urlObject.pathname API

View Discussion
Improve Article
Save Article
  • Last Updated : 14 Oct, 2021
View Discussion
Improve Article
Save Article

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:




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); 


Output:

/a/b

Example 2:




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); 


Output:

/

Supported Browsers:

  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!