Skip to content
-
What is Express?
Last Updated :
23 Jul, 2025
Express is a minimal and flexible web application framework for NodeJS. It provides a robust set of features for building dynamic web applications and APIs, making it one of the most popular frameworks used in the development of web applications on the server side.
- Simplifies routing and middleware management.
- Supports various template engines for dynamic content.
- Provides rapid development with a robust set of features.
What is Express?Prerequisites: JavaScript, NodeJS
Why Use Express?
- Minimal and Flexible: Express is unopinionated, which means it does not force developers to follow a particular structure or design pattern. It offers just the essentials and allows developers to decide how to structure their application.
- Speed: Express is highly efficient due to its minimalistic nature. This makes it a great choice for applications that need high-performance and low overhead.
- Middleware: Express has a built-in middleware framework that allows you to add various functions such as authentication, logging, and error handling to your application without cluttering the core business logic.
- Routing: Express provides a powerful routing system that is flexible and easy to use for defining HTTP routes for handling requests like GET, POST, PUT, DELETE, etc.
- Template Engine Support: Express supports various template engines like EJS, Pug, and Handlebars, making it easier to build dynamic HTML pages.
Features of ExpressJS
1. Routing
- Defines how an application's endpoints respond to client requests.
- Simplifies handling of different HTTP methods (GET, POST, etc.) at various URL paths.
- Enables creation of clean and maintainable URL structures.
2. Middleware
- Functions that execute during the request-response cycle.
- Facilitates tasks like logging, authentication, and parsing request bodies.
- Allows modular addition of functionalities to applications.
3. Error Handling
- Provides mechanisms to manage application errors gracefully.
- Supports both synchronous and asynchronous error handling.
- Enables centralized error management for consistent responses.
4. Request & Response Objects
- Enhances NodeJS's req and res objects with additional methods.
- Simplifies tasks like redirecting, rendering, and sending responses.
- Provides utilities for handling query parameters and form data.
5. Body Parsing
- Parses incoming request bodies in various formats (e.g., JSON, URL-encoded).
- Simplifies access to data sent by clients in POST requests.
- Eliminates the need for manual parsing of incoming data.
How Does Express Work?
- Request-Response Cycle: When a client (e.g., a browser) sends a request to a server, Express processes the request based on the route and method specified. The application processes the request through various middleware functions and eventually sends back an HTTP response.
- Middleware Flow: Middleware functions are executed in the order they are defined in the code. They handle incoming requests, perform operations on the request object (such as validating data or modifying headers), and pass control to the next middleware or route handler.
- Routing: Express matches the incoming request to the appropriate route based on the URL path and HTTP method (GET, POST, etc.). Once a match is found, Express executes the associated route handler.
- Rendering Views: Express supports rendering views using template engines, which can dynamically generate HTML based on data passed from the route handlers.
Use Express in your Node Application
Step 1: In the existing Node Application install Express.
npm install express
The updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18",
"react-dom": "^18",
"express": "^4.17.3",
},
Step 2: In the app.js file add the following code.
JavaScript
//app.js
const express = require('express');
const app = express();
const PORT = 4000;
// Define a basic route
app.get('/', (req, res) => {
res.send('Welcome To GeeksforGeeks!');
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Step 3: To start the application run the following command.
node app.js
Output
Running Express ApplicationAdvantages of Express
- Simplifies web server development on NodeJS.
- Offers a minimalist and flexible framework for scalability.
- Enhances code readability and maintainability.
- Accelerates development with a feature-rich API.
- Facilitates a vibrant ecosystem for easy integrations.
Disadvantages of Express
- Limited support for real-time applications out of the box.
- Asynchronous code can lead to callback hell (callback-based nested code).
- Relatively steeper learning curve for beginners compared to simpler frameworks.
- Express itself is unopinionated, which may require additional decision-making on project structure.
- Less built-in functionality compared to larger frameworks like Django or Ruby on Rails.
Similar Reads
What is HTML? HTML (HyperText Markup Language) is the standard markup language used to structure web pages. It is used to create various elements of a webpage/website such as nav-bar, paragraphs, images, video, Forms, and more, which are displayed in a web browser.HTML uses tags to create elements of a webpage.It
3 min read
What is CSS? CSS, which stands for Cascading Style Sheets is a language in web development that enhances the presentation of HTML elements. By applying styles like color, layout, and spacing, CSS makes web pages visually appealing and responsive to various screen sizes.CSS allows you to control the look and feel
5 min read
What is JavaScript? JavaScript is a powerful and flexible programming language for the web that is widely used to make websites interactive and dynamic. JavaScript can also able to change or update HTML and CSS dynamically. JavaScript can also run on servers using tools like Node.js, allowing developers to build entire
6 min read
What is JSON? JSON (JavaScript Object Notation) is a lightweight text-based format for storing and exchanging data. It is easy to read, write, and widely used for communication between a server and a client.Key points:JSON stores data in key-value pairs.It is language-independent but derived from JavaScript synta
3 min read
What is NPM & How to use it ? NPM, short for Node Package Manager, is the default package manager for NodeJS. It is a command-line utility that allows you to install, manage, and share packages or modules of JavaScript code. These packages can range from small utility libraries to large frameworks, and they can be easily integra
3 min read
What is React? React JS is a free library for making websites look and feel cool. It's like a special helper for JavaScript. People from Facebook and other communities work together to keep it awesome and up-to-date. React is Developed by Facebook, React is a powerful JavaScript library used for building user inte
6 min read
What is React Router? React Router is like a traffic controller for your React application. Just like how a traffic controller directs vehicles on roads, React Router directs users to different parts of your app based on the URL they visit. So, when you click on a link or type a URL in your browser, React Router decides
2 min read
What is Material UI ? Material UI is a popular React UI framework that provides pre-designed components following Google's Material Design guidelines. It simplifies the process of creating sleek and responsive user interfaces by offering a library of customizable components. Default Installationnpm install @mui/material
1 min read
What is Node? Node is a JavaScript runtime environment that enables the execution of code on the server side. It allows developers to execute JavaScript code outside of a web browser, enabling the development of scalable and efficient network applications. Table of Content What is Node?Steps to setup the Node App
3 min read
What is Express? Express is a minimal and flexible web application framework for NodeJS. It provides a robust set of features for building dynamic web applications and APIs, making it one of the most popular frameworks used in the development of web applications on the server side.Simplifies routing and middleware m
5 min read
`;
$(commentSectionTemplate).insertBefore(".article--recommended");
}
loadComments();
});
});
function loadComments() {
if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) {
if (!isfollowingApiCall) {
isfollowingApiCall = true;
setTimeout(function(){
if (loginData && loginData.isLoggedIn) {
if (loginData.userName !== $('#followAuthor').val()) {
is_following();
} else {
$('.profileCard-profile-picture').css('background-color', '#E7E7E7');
}
} else {
$('.follow-btn').removeClass('hideIt');
}
}, 3000);
}
}
});
}
$(".accordion-header").click(function() {
var arrowIcon = $(this).find('.bottom-arrow-icon');
arrowIcon.toggleClass('rotate180');
});
});
window.isReportArticle = false;
function report_article(){
if (!loginData || !loginData.isLoggedIn) {
const loginModalButton = $('.login-modal-btn')
if (loginModalButton.length) {
loginModalButton.click();
}
return;
}
if(!window.isReportArticle){
//to add loader
$('.report-loader').addClass('spinner');
jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', {
PRACTICE_API_URL: practiceAPIURL,
PRACTICE_URL:practiceURL
},function(responseTxt, statusTxt, xhr){
if(statusTxt == "error"){
alert("Error: " + xhr.status + ": " + xhr.statusText);
}
});
}else{
window.scrollTo({ top: 0, behavior: 'smooth' });
$("#report_modal_content").show();
}
}
function closeShareModal() {
const shareOption = document.querySelector('[data-gfg-action="share-article"]');
shareOption.classList.remove("hover_share_menu");
let shareModal = document.querySelector(".hover__share-modal-container");
shareModal && shareModal.remove();
}
function openShareModal() {
closeShareModal(); // Remove existing modal if any
let shareModal = document.querySelector(".three_dot_dropdown_share");
shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" }));
document.querySelector(".hover__share-modal-container").append(
Object.assign(document.createElement('div'), { className: "share__modal" }),
);
document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" }));
const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"];
socialOptions.forEach((socialOption) => {
const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" });
const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` });
const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` });
const shareLink = (socialOption === "Copy Link") ?
Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) :
Object.assign(document.createElement('a'), { className: "link-container" });
if (socialOption === "LinkedIn") {
shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`);
shareLink.setAttribute('target', '_blank');
}
if (socialOption === "WhatsApp") {
shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
if (socialOption === "Twitter") {
shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
shareLink.append(icon, socialText);
socialContainer.append(shareLink);
document.querySelector(".share__modal").appendChild(socialContainer);
//adding copy url functionality
if(socialOption === "Copy Link") {
shareLink.addEventListener("click", function() {
var tempInput = document.createElement("input");
tempInput.value = window.location.href;
document.body.appendChild(tempInput);
tempInput.select();
tempInput.setSelectionRange(0, 99999); // For mobile devices
document.execCommand('copy');
document.body.removeChild(tempInput);
this.querySelector(".share__option-text").textContent = "Copied"
})
}
});
// document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu"));
}
function toggleLikeElementVisibility(selector, show) {
document.querySelector(`.${selector}`).style.display = show ? "block" : "none";
}
function closeKebabMenu(){
document.getElementById("myDropdown").classList.toggle("show");
}