測試代碼:javascript
console.log('*** app start ***'); console.log('*** module.filename = ' + module.filename + ' ***'); console.log('*** __filename = ' + __filename + ' ***'); console.log('*** __dirname = ' + __dirname + ' ***'); console.log('*** process.cwd() = ' + process.cwd() + ' ***'); console.log('*** require.main.filename= ' + require.main.filename + ' ***'); console.log('*** app end ***');
結論:java
require()方法的座標路徑是:module.filename;fs.readFile()的座標路徑是:process.cwd()。node