Horje
Node.js 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: In this example, we will see the use of urlObject.pathname()

javascript

const url = require('url');
     
const address = 
   
// Parse the address:
const q = url.parse(address, true);
   
/* The parse method returns an object containing
 URL properties */
   
console.log(q.pathname);

Output:

/a/b

Example 2: In this example, we will see the object containing URL properties

javascript

const url = require('url');
     
const address = 
   
// Parse the address:
const q = url.parse(address, true);
   
/* The parse method returns an object containing
 URL properties */
   
console.log(q.pathname);

Output:

/

Supported Browsers:

  • Google Chrome
  • Edge
  • Opera
  • Apple Safari
  • Firefox


Reffered: https://www.geeksforgeeks.org


Node.js

Related
Node.js URLSearchParams.set() Node.js URLSearchParams.set()
Node.js URLSearchParams.toString() Node.js URLSearchParams.toString()
Node.js URL.domainToASCII Node.js URL.domainToASCII
Node.js URL.domainToUnicode Node.js URL.domainToUnicode
Node.js urlObject.port API Node.js urlObject.port API

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12