Node.js urlObject.path Property
In this article, we will be learning about urlObject.path API. urlObject.path API property is a concatenation of the pathname and search components. Pathname refers to the file path in an URL and search components refer to the query and hash string which has fixed limits such as question mark (?) or hash (#) characters decoding of the path is performed.
Example: Let us consider an URL ‘http://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash’
Syntax:
urlObject.path
Return Value:
'/p/a/t/h?query=string'
urlObject.path returns ‘/p/a/t/h?query=string’ after it is returned by the url.parse() function.
Example 1: Index.js
Javascript
const http = require( 'url' );
const myURL =
const q = http.parse(myURL, true );
console.log(q.path);
|
Execution command:
node index.js
Console Output:
/p/a/t/h?query=string
Example 2:(Changing the path)
Javascript
const http = require( 'url' );
const myURL =
const q = http.parse(myURL, true );
console.log( "Before Change" );
console.log(q.path);
console.log();
q.path = '/s/k/t/j?query=abc@gmail.com'
console.log( "After Change" );
console.log(q.path);
|
Execution command:
node index.js
Console Output:
Before Change
/p/a/t/h?query=string
After Change
/s/k/t/j?query=abc@gmail.com
Last Updated :
05 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...