express和http之间的技术区别是什么,就此而言进行连接 [英] what's the technical difference between express and http, and connect for that matter
问题描述
var express = require("express")
, app = express()
, http = require("http").createServer(app)
我经常看到这些依赖项.从我的理解来看,http托管前端html?和表达拥有服务器端的nodejs逻辑?并且连接是express的基础层,那么服务器端模块也是吗?
I constantly see these being put on the dependencies. From my point of understanding, http hosts front-end html? and express holds server-sided nodejs logic? and connect was the base layer of express so is that also a server-sided module?
如果不是这种情况,为什么人们不这样做
If that's not the case why not people just do
express().listen(8080)
代替
require("http").createServer(express()).listen(8080)
推荐答案
Express
是http
之上的另一层.它负责Web应用程序所需的基本重复任务. connect
是一种中间件,它也可以处理Web应用程序所需的基本重复任务.
Express
is another layer on top of http
. It takes care of basic repeated tasks that are required for an web application. connect
is a middleware, which too takes care of basic repeated tasks that are required for an web application.
使用任何框架背后的整个想法是保持 DRY ,不要重复自己.每个Web应用程序都非常需要诸如解析正文,解析cookie 之类的任务. Express
通过默认提供它们.
The whole idea, behind using any framework is to stay DRY, Don't Repeat Yourself. Tasks like, parsing the body of the request, parsing cookies are very much required for every web-application. Express
provides them by default.
在Express 4.x中,大多数已重构为几个粒度模块,例如body-parser
,morgan
等.一个人可以直接使用它们而无需使用express.
有关完整的模块集,请参考 Express-GitHub .
In the Express 4.x, most of it has been refactored in to several granular modules, like body-parser
, morgan
etc. One can use them directly without using express.
Please refer Express - GitHub for complete set of modules.
Express
是http
之上的另一层,表示Express
在内部使用http
.换句话说,它是http
的包装.如果查看Express
的源代码,您会发现它在内部使用http
.请参考突出显示的声明,网址为
https://github.com/strongloop/express/blob /master/lib/application.js#L540-543
Express
is another layer on top of http
means Express
internally uses http
. In other words, it is a wrapper over http
. If you look at the source code of Express
, you will find that it internally uses http
. Please refer the highlighted statements at
https://github.com/strongloop/express/blob/master/lib/application.js#L540-543
这篇关于express和http之间的技术区别是什么,就此而言进行连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!