Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 349
Koushik Das Avatar asked Feb 03 '16 03:02

Koushik Das


People also ask

What is the difference between HTTP Server and Express server?

HTTP is an independent module. Express is made on top of the HTTP module. HTTP module provides various tools (functions) to do things for networking like making a server, client, etc. Express along with what HTTP does provide many more functions in order to make development easy.

What is HTTP createServer in NodeJS?

The http. createServer() method turns your computer into an HTTP server. The http. createServer() method creates an HTTP Server object. The HTTP Server object can listen to ports on your computer and execute a function, a requestListener, each time a request is made.

Why should you separate Express APP and server in NodeJS?

Faster testing execution. Getting wider coverage metrics of the code. Allows deploying the same API under flexible and different network conditions. Better separation of concerns and cleaner code.


1 Answers

Ultimately, express uses node's http api behind the scenes.

express framework

The express framework provides an abstraction layer above the vanilla http module to make handling web traffic and APIs a little easier. There's also tons of middleware available for express (and express-like) frameworks to complete common tasks such as: CORS, XSRF, POST parsing, cookies etc.

http api

The http api is very simple and is used to to setup and manage incoming/outgoing ,HTTP connections. Node does most of the heavy lifting here but it does provide things you'll commonly see throughout most node web framework such as: request/response objects etc.

like image 118
Sean3z Avatar answered Sep 18 '22 18:09

Sean3z