express里http.createServer和app.listen有什么区别? – CNode技术社区
搜了一下,并看了koa和express这部分的代码:
koa:
/**
* Shorthand for:
*
* http.createServer(app.callback()).listen(…)
*
* @param {Mixed} …
* @return {Server}
* @api public
*/
listen() {
debug('listen');
const server = http.createServer(this.callback());
return server.listen.apply(server, arguments);
}
express:
/**
* Listen for connections.
*
* A node http.Server
is returned, with this
* application (which is a Function
) as its
* callback. If you wish to create both an HTTP
* and HTTPS server you may do so with the “http”
* and “https” modules as shown here:
*
* var http = require(‘http’)
* , https = require(‘https’)
* , express = require(‘express’)
* , app = express();
*
* http.createServer(app).listen(80);
* https.createServer({ … }, app).listen(443);
*
* @return {http.Server}
* @public
*/
app.listen = function listen() {
var server = http.createServer(this);
return server.listen.apply(server, arguments);
};
综合koa和express的代码,可以看出,没有区别,但是这两个框架默认都是使用http,若使用https则需要自己收写。