- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
NodeJS - urlObject.path Property
The NodeJS urlObject.path property of urlObject is a combination of both pathname and search portions. This property specifies the path segment along with the search portion if present. This property does not perform the decoding of the path segment.
For instance, consider a URL “https://user:pass@site.com:80000/例?q=pas#hash”.
“/例?q=pas” is the path segment.
“/例” is the pathname portion.
“?q=pas” is the search portion.
The path segment contains a character ‘例’, if it is decoded the value will be “xn--fsq/”. As the NodeJs path property does not perform the decoding, the returned value will be “https://user:pass@Site.com/例#hash”.
Syntax
Following is the syntax of the NodeJS urlObject.path property
urlObject.path
Parameters
This property does not accept any parameters.
Return Value
This property retrieves the path segment of a URL along with the search portion if present.
Example
If the specified URL contains a path segment, the NodeJS path property will retrieve that segment.
In the example below, we are trying to get the path segment from the specified URL.
const url = require('url'); let address = 'https://user:pass@site.com:80000/pa/th#hashh'; let result = url.parse(address, true); console.log(result.path);
Output
As we can see in the output below, the NodeJS path property retrieved the path segment from the URL.
/pa/th
Example
If the provided URL contains the path segment, the path property will retrieve that segment including the search portion if present.
In the following example, we are also including the search portion along with the path segment to the URL.
const url = require('url'); let address = 'https://user:pass@site.com:80000/pa/th?q=val#hashh'; let result = url.parse(address, true); console.log(result.path);
Output
Following is the output of the above code
The path property will retrieve the path segment along with search portions as it is present in the given URL.
/pa/th?q=val
Example
If the provided URL string is not parsed using the NodeJS parse() method, the NodeJS path property will be undefined.
In the following example, we are not parsing the URL string.
const url = require('url'); let address = 'https://user:pass@site.com:8000/pa/th?q=val#hashh'; console.log(address.path);
Output
Following is the output of the above code
undefined
To Continue Learning Please Login
Login with Google