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:
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:
- 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.username API
- Node | URL.port API
- Routing in Node.js
- Node | URL.origin API
- Node | URL.host API
- Node | URL.hostname 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.



