Node.js Path Module

The path module in Node.js is used to work with file and directory paths.

Example

const path = require("path");

const filePath = "/students/projects/index.html";

console.log("File name:", path.basename(filePath));
console.log("Extension:", path.extname(filePath));
console.log("Directory:", path.dirname(filePath));
        
Example Output:

File name: index.html
Extension: .html
Directory: /students/projects

Common Path Methods

← Back to Home