file: /config/index.js;
var config = {
local: {
mode: 'local',
port: 3000
},
staging: {
mode: 'staging',
port: 4000
},
production: {
mode: 'production',
port: 5000
}
}
module.exports = function(mode) {
return config[mode || process.argv[2] || 'local'] || config.local;
}
file: app.js;
...
var config = require('./config')();
...
http.createServer(app).listen(config.port, function(){
console.log('Express server listening on port ' + config.port);
});
config[mode || process.argv[2] || 'local'] || config.local;
的含义是什么?
已知信息如下:
1) ||
表示 "或"。
2) 当在终端输入 node app.js staging
时,process.argv[2]
获取 NODE.JS 命令行中的第二个参数,因此它是 "staging"。
请问有人能够解释这些代码片段吗?
||
表示或者
。 - Ben Fortune