源码结构

-
首先我们去
package.json
文件中查找main
字段来确定入口文件在哪里 -
但是我们并没有发现
main
字段,说明入口文件是根目录下的index.js
文件module.exports = require('./lib/express');
-
我们又发现
index.js
文件引用了./lib/express
导出的模块,其它的代码文件都是来辅助实现express.js
// express.js 部分代码 exports = module.exports = createApplication; function createApplication() { var app = function(req, res, next) { app.handle(req, res, next); }; mixin(app, EventEmitter.prototype, false); mixin(app, proto, false); // expose the prototype that will get set on requests app.request = Object.create(req, { app: { configurable: true, enumerable: true, writable: true, value: app } }) // expose the prototype that will get set on responses app.response = Object.create(res, { app: { configurable: true, enumerable: true, writable: true, value: app } }) app.init(); return app; }
-
至此我们大概了解了express 的源码结构
...大约 7 分钟