[英]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)
I constantly see these being put on the dependencies. 我经常看到这些依赖于它们。 From my point of understanding, http hosts front-end html? 从我的理解,http主机前端html? and express holds server-sided nodejs logic? 和express保存服务器端的nodejs逻辑? and connect was the base layer of express so is that also a server-sided module? 和connect是express的基础层,所以也是服务器端模块?
If that's not the case why not people just do 如果不是这样的话,人们就不会这样做
express().listen(8080)
instead of 代替
require("http").createServer(express()).listen(8080)
Express
is another layer on top of http
. Express
是http
之上的另一层。 It takes care of basic repeated tasks that are required for an web application. 它负责Web应用程序所需的基本重复任务。 connect
is a middleware, which too takes care of basic repeated tasks that are required for an web application. connect
是一个中间件,它也负责Web应用程序所需的基本重复任务。
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. 每个Web应用程序都非常需要解析请求主体 , 解析cookie等任务。 Express
provides them by default . Express
默认提供它们。
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. 在Express 4.x中,大部分已经被重构为几个粒度模块,如body-parser
, morgan
等。可以直接使用它们而不使用express。 Please refer Express - GitHub for complete set of modules. 有关完整的模块集,请参阅Express - GitHub 。
Express
is another layer on top of http
means Express
internally uses http
. Express
是http
之上的另一层,意味着Express
内部使用http
。 In other words, it is a wrapper over http
. 换句话说,它是http
的包装器。 If you look at the source code of Express
, you will find that it internally uses http
. 如果你看一下Express
的源代码,你会发现它在内部使用http
。 Please refer the highlighted statements at https://github.com/strongloop/express/blob/master/lib/application.js#L540-543 请参阅https://github.com/strongloop/express/blob/master/lib/application.js#L540-543上突出显示的声明
Lets take an example to understand the difference between http
module and express
module. 让我们举一个例子来理解http
模块和express
模块之间的区别。
for an instance consider http
module is a car ie an average comercial car. 例如, http
模块是一辆汽车,即一辆普通的商用汽车。
where on the other hand, consider express
as a super car. 另一方面,考虑express
为超级跑车。
See, http
module provides various tools (functions) to do things for networking like making a server
, cilent
etc. 请参阅, http
模块提供各种工具(功能)来做网络的事情,如制作server
, cilent
等。
where as express
is build upon the top of http
module with some more usable and better functionalities like easy ways to handle routes
,easy ways to make firmware, servers, client
etc. express
是建立在http
模块顶部的地方,有一些更实用,更好的功能,比如简单的方法来处理routes
,简单的方法来制作firmware, servers, client
等。
just like a difference between normal car and super car (may be luxury car) .They both are cars at the end of the day but features are more in luxury car with ease of use just like in express.js
就像普通汽车和超级汽车(可能是豪华车)之间的区别一样。它们都是一天结束时的汽车,但功能更多的是豪华车,易于使用,就像在express.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.