Node.js and Express are two essential tools in the JavaScript ecosystem, especially for server-side development. While they are often used together, they serve different purposes. This article will explain what Node.js and Express are, their key differences, and when to use each.
Node JS
Node JS is an open-source and cross-platform runtime environment for executing JavaScript code outside of a browser. You need to remember that Node JS is not a framework and it’s not a programming language. Most people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end services like APIs for Web Apps or Mobile Apps. It’s used in production by large companies such as Paypal, Uber, Netflix, Walmart, and so on.
Express JS
Express is a small framework that sits on top of Node JS’s web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing. It adds helpful utilities to Node JS’s HTTP objects. It facilitates the rendering of dynamic HTTP objects.
Note: These codes are covered in the below comparisons.
Example: The following comparison shows how the same code is written differently in Node.js (Left tab code) and Express.js (Right tab code).

While Node.js provides the runtime, Express is a web framework that simplifies building server-side applications.
Below are basic examples of creating a server in Node JS & Express JS
Express JS Server:
Step to Install Express: Install Express using the following command.
npm i --save express
JavaScript
// Filename - index.js
// Requiring the module
const express = require('express');
const app = express();
// Route handling
app.get('/', (req, res) => {
res.send('<h2>Hello from Express.js server!!</h2>');
});
// Server setup
app.listen(8080, () => {
console.log('server listening on port 8080');
});
Steps to Run the Server: Run the index.js file using the following command:
node index.js
Output:
Node JS Server:
Require the HTTP module using the following code:
const http = require('http');
JavaScript
// Filename - index.js
// Requiring the module
const http = require('http');
// Creating server object
const server = http.createServer(
(req, res) => {
res.setHeader('Content-Type', 'text/html');
res.write('<html>');
res.write(
'<head><title>GeeksforGeeks</title><head>'
);
res.write(
'<body><h2>Hello from Node.js server!!</h2></body>'
);
res.write('</html>');
res.end();
});
// Server setup
server.listen(3000, () => {
console.log("Server listening on port 3000")
});
Steps to Run the Server:
node index.js
Output:

Routing in Express JS
Routing in Express.js simplifies implementation, offering ease of use. Through Express's built-in functions, we can directly specify route names and associated functions, indicating the type of request, whether it's a GET or POST, for instance. This streamlined approach streamlines the development process, enhancing productivity and reducing complexity.
JavaScript
// Filename - index.js
// Requiring module
const express = require('express');
const app = express();
// Handling '/' request
app.get('/', (req, res) => {
res.send('<h2>Hello from Express.js server!!</h2>');
});
// Handling '/about' request
app.get('/about', (req,res) => {
res.send('<h2>GeeksforGeeks- Express.js</h2>');
});
// Server setup
app.listen(8080, () => {
console.log('server listening on port 8080');
});
Steps to Run the Server: Run the index.js file using the following command:
node index.js
Open your browser and go to http://localhost:8080/about, following will be the output:

Routing in Node JS
In Node.js, routing isn't inherently provided. Instead, developers must manually inspect the URL and method of each incoming request to determine how to handle and respond to it appropriately. This means that routing logic needs to be implemented within the application code, typically through conditional statements or frameworks like Express.js, which offer more structured routing capabilities. By checking the URL and method of each request, developers can tailor responses dynamically based on the specific requirements of the application.
JavaScript
// Filename - index.js
// Requiring the module
const http = require('http');
// Creating server object
const server = http.createServer((req, res) => {
const url = req.url;
if(url === '/') {
res.write('<html>');
res.write(
'<head><title>GeeksforGeeks</title><head>');
res.write(
'<body><h2>Hello from Node.js server!!</h2></body>');
res.write('</html>');
return res.end();
}
if(url === '/about') {
res.write('<html>');
res.write(
'<head><title>GeeksforGeeks</title><head>');
res.write(
'<body><h2>GeeksforGeeks- Node.js</h2></body>');
res.write('</html>');
return res.end();
}
});
// Server setup
server.listen(3000, () => {
console.log("Server listening on port 3000")
});
Steps to Run the Server:
node index.js
Output: Open your browser and go to http://localhost:3000/about:

Difference between Node JS and Express JS
- Node JS is a platform for building I/O applications that are server-side event-driven and made using JavaScript.
- Express JS is a framework based on Node JS which is used for building web applications using approaches and principles of Node JS's event-driven architecture.
Feature | Express JS | Node JS |
---|
Usage | It is used to build web apps using approaches and principles of Node JS | It is used to build server-side, input-output, event-driven apps. |
Level of features | More features than Node JS. | Fewer features. |
Building Block | It is built on Node JS | It is built on Google’s V8 engine. |
Written in | JavaScript | C, C++, JavaScript |
Framework/Platform | Framework based on Node JS | Run-time platform or environment designed for server-side execution of JavaScript. |
Controllers | Controllers are provided. | Controllers are not provided. |
Routing | Routing is provided. | Routing is not provided. |
Middleware | Uses middleware for the arrangement of functions systematically server-side. | Doesn’t use such a provision. |
Coding time | It requires less coding time. | It requires more coding time. |
Similar Reads
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
JavaScript Interview Questions and Answers JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as
15+ min read
React Tutorial React is a JavaScript Library known for front-end development (or user interface). It is popular due to its component-based architecture, Single Page Applications (SPAs), and Virtual DOM for building web applications that are fast, efficient, and scalable.Applications are built using reusable compon
8 min read
Difference Between IPv4 and IPv6 In the digital world, where billions of devices connect and communicate, Internet Protocol (IP) Addresses play a crucial role. These addresses are what allow devices to identify and locate each other on a network.To know all about IP Addresses - refer to What is an IP Address?Currently, there are tw
9 min read
Decorators in Python In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are
10 min read
AVL Tree Data Structure An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w
8 min read
Sliding Window Technique Sliding Window Technique is a method used to solve problems that involve subarray or substring or window. The main idea is to use the results of previous window to do computations for the next window. This technique is commonly used in algorithms like finding subarrays with a specific sum, finding t
13 min read