下兔子洞 - “res”在express和/或nodejs中来自哪里
Down the rabbit hole - Where does "res" originate from in express and/or nodejs?
我试图更多地了解 express 和 nodejs 的内部结构。在 express' response.js
文件中查找,它经常将几种方法分配给res
,这似乎是一个原型。
具体来说,res
被声明为 res = http.ServerResponse.prototype
.
好的,那么http
是什么? http
声明为 http = require('http')
。
因此,在快递http.js
文件中,我们看到exports = module.exports = HTTPServer;
HTTPServer
似乎是这种方法:
function HTTPServer(middleware){
connect.HTTPServer.call(this, []);
this.init(middleware);
};
这就是我陷入困境的地方。根据我的逻辑,似乎ServerResponse
是在HTTPServer
方法上调用的,这当然没有意义。因此,我一定错过了什么。
更新:
我刚刚意识到 express 创建了一个 HTTPServer 实例:
exports.createServer = function(options){
if ('object' == typeof options) {
return new HTTPSServer(options, Array.prototype.slice.call(arguments, 1));
} else {
return new HTTPServer(Array.prototype.slice.call(arguments));
}
};
所以我猜是不是在这种情况下调用了ServerResponse
?但是我仍然无法找到ServerResponse
...
我在快速源文件中看不到任何http.js文件。
根据node.js http http = require('http')
的文档将加载http模块,该模块具有ServerResponse
对象。
因此,表达式代码通过其他方法增强了 ServerResponse 对象。
相关文章:
- nodejs-expressjs上传图像并显示它们
- TypeError:在不兼容的接收器nodejs上调用了方法Uint8Array.length
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- NodeJS日期格式不起作用
- Nested Q.all nodejs
- Nodejs API控制器,用于在API之间切换
- 否'访问控制允许来源'标头存在于IISNOde中请求的资源(AngularJS+NodeJs)上
- 如何在大型nodeJS代码的基础上逐步引入typescript
- 在Nodejs中Express输入DEBUG=app时权限被拒绝/bin
- 无法使用nodeJS在html中设置Image src
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- NodeJS API调用中Array中的Push和Pull元素
- 基于api密钥的NodeJS web服务
- 在gump和nodejs中使用Typescript时,未定义对require和exports的引用
- “util.inherits”和在NodeJS中扩展原型之间的区别
- 将一个方法转换为promise:Nodejs
- nodejs中匿名函数的使用
- Node和Nodejs版本不同
- Nodejs服务器在解析之前生成输入表单
- 下兔子洞 - “res”在express和/或nodejs中来自哪里