Node.js - Path
Thu Apr 07 2022 08:35:09 GMT+0000 (Coordinated Universal Time)
Saved by
@monkeyDo
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">
content_copyCOPY
Comments