HTTP and Express both are used in NodeJS for development. In this article, we’ll go through HTTP and express modules separately
HTTP: It is an in-build module which is pre-installed along with NodeJS. It is used to create server and set up connections. Using this connection, data sending and receiving can be done as long as connections use a hypertext transfer protocol.
Example: Creating a server using the HTTP module in NodeJS.
index.js
var http = require( 'http' );
http.createServer( function (req, res) {
res.write( 'Hello World!' );
res.end();
}).listen(3000);
|
Run the index.js file using the following command.
node index.js
Output:

Express: Express as a whole is known as a framework, not just as a module. It gives you an API, submodules, functions, and methodology and conventions for quickly and easily typing together all the components necessary to put up a modern, functional web server with all the conveniences necessary for that (static asset hosting, templating, handling CSRF, CORS, cookie parsing, POST data handling, and many more functionalities.
Module Installation: You can install the express module using the following command.
npm i express
Example: Creating a server using the express module in NodeJS.
index.js
const express = require( 'express' );
const app = express();
app.get( '/' , function (req, res) {
res.send( "Hello World!, I am server created by expresss" );
})
app.listen(3000, function () {
console.log( "server started" );
})
|
Run the index.js file using the following command.
node index.js
Output:

Difference between HTTP module and Express.js module:
HTTP
|
Express
|
HTTP comes inbuilt along with NodeJS that is, we don’t need to install it explicitly. |
Express is installed explicitly using npm command: npm install express |
HTTP is not a framework as a whole, rather it is just a module. |
Express is a framework as a whole. |
HTTP does not provide function for static hosting, you require to write your own. |
Express provide express.static function for static asset hosting. Example: app.use(express.static(‘public’)); |
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. |
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Jul, 2022
Like Article
Save Article