path is a built-in utility that builds file paths correctly regardless of the operating system. Since Windows uses \ and macOS/Linux use /, it's safer to use path.join() than to concatenate strings by hand.
const path = require('path');
const filePath = path.join(__dirname, 'uploads', 'profile.png');
console.log('Full Path:', filePath);
console.log('File Name:', path.basename(filePath));
console.log('Folder:', path.dirname(filePath));
console.log('Extension:', path.extname(filePath));__dirname returns the path of the folder the current file is in. path.join() joins path segments together in a way that matches the OS. basename, dirname, and extname pull out different pieces of file info.
Full Path: /your-project/uploads/profile.png File Name: profile.png Folder: /your-project/uploads Extension: .pngInfo
For upload file paths, image paths, template paths, and static file paths, using path.join() cuts down on cross-platform issues.