Unique features of Express JS

Last Updated : 12 Aug, 2026

Express.js is a lightweight and powerful web framework built for Node.js. It simplifies building web applications and APIs by providing essential features that help developers create scalable, high-performance applications easily. Let's explore the unique features of Express.js that make it a popular choice for web development.

frame_19

1. Minimalist Framework

Express.js is lightweight and focuses on only the essential features needed to create a web server or API.

You can get started with Express in just a few lines of code, without unnecessary complexity. It helps you set up routes, handle requests, and send responses quickly.

JavaScript
//app.js
const express = require('express');
const app = express();

// Define a simple route
app.get('/', (req, res) => {
  res.send('Hello, Express!');
});

// Start the server
app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Output

Screenshot-2025-03-05-142223
Minimalist Framework
  • Minimal Setup: Just a few lines of code to define a route and start the server.
  • Route: The app.get() method defines a route that responds with "Hello, Express!" when the home page (/) is accessed.
  • Server Initialization: The app.listen() method starts the server on port 3000.

2. Powerful Routing System

Express.js provides a powerful routing system that allows you to define routes for different HTTP methods (GET, POST, PUT, DELETE) and URLs. This makes it flexible for handling various requests.

JavaScript
const express = require('express');
const app = express();
// GET request route
app.get('/about', (req, res) => {
    res.send('About us');
  });
  // POST request route
  app.post('/submit', (req, res) => {
    res.send('Form submitted');
  });
// Start the server
app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Output:

GET (/about) Route:

Screenshot-2025-03-05-143047
/about route

Post(/submit) Route:

Screenshot-2025-03-05-143404
/submit route
  • Define a GET route: app.get('/about', (req, res) => { res.send('About us'); }); sets up a route for /about that responds with "About us" when accessed via GET request.
  • Define a POST route: app.post('/submit', (req, res) => { res.send('Form submitted'); }); sets up a route for /submit that responds with "Form submitted" when a POST request is made.
  • Start the server: app.listen(3000, () => { console.log('Server is running on http://localhost:3000'); }); starts the server on port 3000 and logs a message when the server is ready.

3. Middleware Support

Express.js allows you to use middleware functions to process requests and responses. Middleware can be applied globally or to specific routes, helping organize your application logic.

JavaScript
const express = require('express');
const app = express();

// Example of a middleware function
app.use((req, res, next) => {
    console.log('Request received at:', Date.now());
    next();  // Pass control to the next middleware or route
  });
  
  // Sample route
  app.get('/home', (req, res) => {
    res.send('Welcome to the home page!');
  });
  
  

// Start the server
app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Output

Screenshot-2025-03-05-144047
middleware function execution
Screenshot-2025-03-05-144040
/home route
  • Middleware Function: Logs the current time whenever a request is received, then passes control to the next step.
  • Route Handling: Defines a route (/home) that sends a welcome message when accessed.
  • Server Initialization: Starts the server on port 3000 and logs a message indicating the server is running.

4. Templating Engines

Express allows you to use various templating engines like Pug, EJS, or Handlebars. Here's an example using EJS to render dynamic content.

  • First, install the ejs package:
npm install ejs
  • Now, set up Express to use EJS and render a dynamic template and also make a folder by the name views and then make a profile.ejs file in it
JavaScript
//profile.ejs
<h1>Profile</h1>
<p>Name: <%= user.name %></p>
<p>Age: <%= user.age %></p>
  • Now make a server.js file and add the below code to it
JavaScript
const express = require('express');
const app = express();
app.set('view engine', 'ejs');

app.get('/profile', (req, res) => {
  const user = { name: 'Pranshi', age: 30 };
  res.render('profile', { user });  // Renders the 'profile.ejs' template
});

// Start the server
app.listen(3000, () => {
    console.log('Server is running on http://localhost:3000');
  });

Output

Screenshot-2025-03-05-150117
/profile route

5. Asynchronous Request Handling

Since Express is built on top of Node.js, it supports asynchronous request handling. This allows the server to handle multiple requests at once without blocking, improving performance.

JavaScript
const express = require('express');
const app = express();
// Asynchronous route handler
app.get('/data', async (req, res) => {
    try {
      const data = await fetchDataFromDatabase();
      res.json(data);
    } catch (err) {
      res.status(500).send('Error fetching data');
    }
  });
  
  async function fetchDataFromDatabase() {
    // Simulate fetching data (e.g., from a database)
    return { id: 1, name: 'Product A' };
  }
  

// Start the server
app.listen(3000, () => {
    console.log('Server is running on http://localhost:3000');
  });

Output

Screenshot-2025-03-05-150519
/data route


  • Sets up an Express app: It imports express and creates an app object to handle requests.
  • Defines an asynchronous route: The /data route is set up to handle GET requests asynchronously. It tries to fetch data using the fetchDataFromDatabase() function.
  • Fetches data: The fetchDataFromDatabase() function simulates fetching data from a database and returns a product with an id and name.
  • Handles errors and responds: If the data is successfully fetched, it sends the data as a JSON response. If there's an error, it sends a 500 error with the message "Error fetching data".

Reason to Use Express.js

  • Minimal and Flexible: Express is lightweight and gives you the freedom to structure your application without unnecessary overhead.
  • Easy to Learn: It provides a simple API and integrates well with other libraries, making it suitable for beginners and experienced developers.
  • Fast Development: Express simplifies routing, middleware, and request handling, allowing you to build web applications and REST APIs quickly.
  • Extensive Middleware Support: Express provides built-in middleware and supports a wide range of third-party middleware for features such as authentication, logging, validation, security, and file uploads.
  • Excellent for REST APIs: Express offers simple routing and request handling, making it one of the most popular frameworks for building RESTful APIs.
  • Built on Node.js: Since Express runs on Node.js, it benefits from Node.js's asynchronous, event-driven architecture, making it efficient for handling multiple concurrent requests.

Use cases of Express.js

  • Building RESTful APIs: Express is widely used to build REST APIs that allow clients to interact with the server using HTTP methods such as GET, POST, PUT, PATCH, and DELETE.
  • Backend for Frontend Applications: Express is commonly used as the backend for React, Angular, Vue, Next.js, and other frontend frameworks by providing APIs, authentication, and database connectivity.
  • Serving Static Files: Express can serve static assets such as HTML, CSS, JavaScript, images, and other files for web applications.
  • Handling User Authentication: Express is used to implement authentication and authorization using sessions, cookies, JWT, and OAuth.
  • Real-time Applications: Express is commonly used with libraries like Socket.IO to build chat applications, live notifications, multiplayer games, and collaborative tools.
  • Microservices: Express is often used to build lightweight microservices that communicate with other services through REST APIs or messaging systems.
  • API Gateway: Express can act as an API gateway by routing client requests to multiple backend services, handling authentication, logging, and request forwarding.
Comment

Explore