Node vs Express

Last Updated : 27 Feb, 2026

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 a runtime environment that allows JavaScript to run outside the browser.

  • It provides built-in modules to handle server-side tasks like file handling, networking, and HTTP requests.
  • It helps developers build backend services and APIs for web and mobile applications.
  • It is commonly used to create scalable and high-performance applications.
  • Many large companies like PayPal, Uber, Netflix, and Walmart use Node.js in production.

Express JS 

Express.js is a lightweight framework built on top of Node.js that simplifies web application development.It enhances Node.js by:

  • Providing a better structure for applications
  • Simplifying routing
  • Supporting middleware for request handling
  • Adding useful utilities for HTTP requests and responses

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.

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:

Node JS Vs Express JS

Express JSNode JS
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.
More features than Node JS.Fewer features.
It is built on Node JSIt is built on Google’s V8 engine.
JavaScriptC, C++, JavaScript
Framework based on Node JSRun-time platform or environment designed for server-side execution of JavaScript.
Controllers are provided.Controllers are not provided.
Routing is provided.Routing is not provided.
Uses middleware for the arrangement of functions systematically server-side.Doesn’t use such a provision.
It requires less coding time.It requires more coding time.
Comment

Explore