I am trying to play around with the MEAN framework. I used their scaffolding available here . But I am getting confused on how the control flow happens from the time we start the server.js [ node server.js
] file.
Adding snippets of some files, the entire code is here
./server.js
var app = require('./config/lib/app');
var server = app.start();
./config/lib/app.js
module.exports.start = function start(callback) {
var _this = this;
_this.init(function (app, db, config) {
// Start the app by listening on <port> at <host>
app.listen(config.port, config.host, function () {
// Create server URL
var server = (process.env.NODE_ENV === 'secure' ? 'https://' : 'http://') + config.host + ':' + config.port;
// Logging initialization
console.log('--');
.....
if (callback) callback(app, db, config);
});
});
};
For eg, where do the parameters come from in _this.init(function (app, db, config){
segment when im only calling app.start();
-
该function (app, db, config){...}
在_this.init(function (app, db, config){...}
只是函数声明 ,执行算不了什么 ,执行都是在这里完成(线26) if (callback) callback(app, db, config);
其中传递的config参数是此处声明的全局变量var config = require('../config')
(第6行), app
参数在此处声明var app = express.init(db);
(第25行),而db
参数是mongooseService.connect
调用(第20行)的结果(数据库实例)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.