如题,谢谢。
下面这个require用法太诡异了,require参数是一个目录,居然可以访问index.js。 和perl太不一样了。不知道MDN里是否有比较规范、详细的说明,一直没找到。
[coolbar@localhost app]$ ls config/
index.js
[coolbar@localhost app]$ cat config/index.js
var config = {
local: {
mode: 'local',
port: 3000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
staging: {
mode: 'staging',
port: 4000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
production: {
mode: 'production',
port: 5000,
mongo: {
host: '127.0.0.1',
port: 27017
}
}
}
module.exports = function(mode) {
return config[mode || process.argv[2] || 'local'] || config.local;
}
[coolbar@localhost app]$ cat test.js
var config = require('./config')();
console.log(config.port);
[coolbar@localhost app]$ node test.js
3000
--
修改:saynothing FROM 218.108.104.*
FROM 218.108.104.*