I'm new to Node.js and Express.js; using the Express.js executable (express) to generate an express application, I'm given the following lines in app.js:
...
var app = express();
http.createServer(app).listen(app.get('port'), function(){
...
});
...
I'm wondering how node's createServer function can accept an express app? Does Node.js natively support Express.js?
Node's http.createServer
method only requires that the parameter passed to it (app
in this case) be callable as a function that it will call on the 'request'
event. So Express just needs to satisfy that basic requirement to integrate with the node.js http server.
app
is just any other object. Node is not natively supporting Express. Express is just emulating the correct parameter for http.createServer()
.
Basically, Node.js
doesnt natively support Express. Express is just a web-framework built on top of Node.js