首页 > 代码库 > nodejs 2017

nodejs 2017

a.js

// 运行  node a.js

var path = require(‘path‘);
console.log(path.resolve()); // 不传参,会返回当前文件的绝对路径 
console.log(__dirname);  // 也是当前文件的绝对路径

console.log(path.resolve(__dirname));
console.log(path.resolve(__dirname,‘../dist/index.html‘)); 
// 路径组合成一个绝对路径  


var b = require(‘./b‘);
console.log(‘b.env: ‘ + b.build.env)
console.log(‘b.index: ‘ + b.build.index)

b.js

var path = require(‘path‘)
module.exports = {
    build:{
        index: path.resolve(__dirname,‘../dist/index.html‘),
        env: ‘testOne‘
    }
}

 

nodejs 2017