Node.js URL.pathname API
Last Updated :
14 Oct, 2021
The url.pathname is an inbuilt application programming interface of class URL with in url module which is used to get and set the pathname portion of the URL.
Syntax:
const url.pathname
Return value: It gets and sets the pathname portion of the URL.
Below programs illustrate the use of url.pathname Method:
Example 1:
Javascript
const http = require('url');
console.log("Before Change");
console.log(myURL.href);
console.log();
myURL.pathname = '/abcdef';
console.log("After Change");
console.log(myURL.href);
|
Output:

Example 2:
Javascript
const http = require('url');
const pathname = myURL.pathname;
console.log("pathname is : " + pathname);
|
Output:

NOTE: The above program will compile and run by using the node myapp.js command on Node.
Reference:
https://nodejs.org/api/url.html#url_url_pathname
Share your thoughts in the comments
Please Login to comment...