const path = require('path');
// Full path of file name
console.log('Full path: ' + __filename);
// Base file name
console.log('Base file name: ' + path.basename(__filename));
// Directory name
console.log('Directory name: ' + path.dirname(__filename));
// File extension
console.log('File extension: ' + path.extname(__filename));
// Create path object
console.log(path.parse(__filename));
// Access path object property ex. base
console.log(path.parse(__filename).base);
// Concatenate paths (join) ex. directory name and /test/hello.html
console.log(path.join(__dirname, 'test', 'hello.html'));<div class="code-box">
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter