Path Module in Node.js
From the Node.js Core Modules cheat sheet ยท File System (fs) ยท verified Jul 2026
Path Module
Work with file and directory paths across platforms
javascript
const path = require('path');
// Join paths
path.join('/users', 'john', 'documents', 'file.txt');
// Get parts
path.dirname('/users/john/file.txt'); // /users/john
path.basename('/users/john/file.txt'); // file.txt
path.extname('file.txt'); // .txt
// Resolve absolute
path.resolve('file.txt');๐ข Essential - Handle paths correctly on all OS
๐ก Always use path.join() not string concatenation
๐ __dirname is current file's directory
โก path.resolve() creates absolute paths
โ ๏ธ Windows uses \ while Unix uses /
๐ Related: process.cwd() for working directory