例子:
const path = require('path');
const dirName = path.dirname(__filename);
例子:
const path = require('path');
const dirName = path.dirname('file.txt'); // 錯誤的文件路徑
例子:
const path = require('path');
const dirName = path.dirname(fileName); // 錯誤的變量名
例子:
const path = require('path');
const dirName = path.dirname(__filename);
console.log(dirName); // 忘記打印結果
例子:
const path = require('path');
const dirName = path.dirname(__filename); // 在瀏覽器端使用