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); |
chevron_right
filter_none
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); |
chevron_right
filter_none
Output:
/
Supported Browsers:
- Google Chrome
- IE
- Edge
- Opera
- Apple Safari
Recommended Posts:
- Node | urlObject.hash API
- Node | URL.format(urlObject) API
- Node | URL.hash API
- Node | URL.host API
- Node | URL.hostname API
- Node | URL.href API
- Node | URL.password API
- Node | URL.origin API
- Node | URL.username API
- Node | URL.search API
- Node | URL.port API
- Node | URL.pathname API
- Node | URL.format API
- Node | urlObject.auth API
- Node | urlObject.protocol API
- Node | urlObject.search API
- Node | URL.resolve(from,to) API
- Node | urlObject.host API
- Node | urlObject.port API
- Node | URL.protocol 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.

