Node.js path.toNamespacedPath() Method
Last Updated :
08 Oct, 2021
Improve
The path.toNamespacedPath() method is used to find the equivalent namespace-prefixed path from the given path. This method is meaningful only on Windows Systems. It would return the same path without modification on POSIX systems. If the path is not a string, it would be returned without modification.
Syntax:
javascript
Output:
javascript
Output:
path.toNamespacedPath( path )Parameters: This function accepts single parameter as mentioned above and described below:
- path: It is an string which contains the path that has to be converted.
// Import the path module
const path = require('path');
let originalPath = "C:\\Windows\\users";
console.log("Original Path:", originalPath);
let nameSpacedPath = path.toNamespacedPath(originalPath);
console.log("Namespaced Path:", nameSpacedPath);
Original Path: C:\Windows\users Namespaced Path: \\?\C:\Windows\usersExample 2:
// Import the path module
const path = require('path');
let originalPath = "C:\\Windows\\users\\..\\admin";
console.log("Original Path:", originalPath);
let nameSpacedPath = path.toNamespacedPath(originalPath);
console.log("Namespaced Path:", nameSpacedPath);
Original Path: C:\Windows\users\..\admin Namespaced Path: \\?\C:\Windows\adminReference: https://nodejs.org/api/path.html#path_path_tonamespacedpath_path