Difference between server with http.createServer and server using expression in node js

What is the difference between creating a server using an http module and creating a server using an express framework in node js? Thanks.

+6
source share
2 answers

Ultimately, express uses the node http api backstage.

express framework

The express structure provides a layer of abstraction over the http-vanilla module to simplify web traffic and API processing. There is also a lot of middleware available for express (and expressive) frameworks for common tasks, such as: CORS, XSRF, POST intelligibility, cookies, etc.

http api

The http api is very simple and is used to configure and manage incoming / outgoing HTTP connections. node does most of the heavy lifting here, but it provides what you usually see in most node web frameworks such as: request / response , etc.

+9
source

Express uses the http module under the hood, app.listen() returns an instance of http. You would use https.createServer if you needed to use the application using HTTPS, since app.listen uses only the http module.

Here is the source for app.listen so you can see the similarities .:

 app.listen = function(){ var server = http.createServer(this); return server.listen.apply(server, arguments); }; 
+6
source

All Articles