Express
Express.js
- Pronunciation
- ik-SPRESS
In short
Express is the most widely used Node.js web framework: a minimal layer that handles routing, requests and responses through a chain of middleware functions.
What is Express?
Express was first released in 2010, soon after Node.js itself, and became the default way to write a Node server. It adds little on top of Node's built-in HTTP module: a router that maps methods and paths such as GET /users/:id to handler functions, helpers for reading the request and sending JSON or files, and a simple way to plug in middleware.
Middleware is the heart of Express. Each request passes through a list of functions in order; each one can read or change the request, send a response, or call next() to hand it on. Logging, parsing JSON bodies, checking authentication, handling CORS and serving static files are all middleware, and thousands of ready-made packages exist for them.
Because it is so small, Express leaves structure to you: how to organize folders, validate input, talk to the database or handle errors. That flexibility made it popular, and it is also why larger teams often adopt opinionated frameworks built around similar ideas, such as NestJS, or newer, faster ones such as Fastify and Hono. Express 5, released in 2024, finally added native support for async error handling.
A common misconception is that Express is a full-stack framework like Django or Rails. It has no ORM, no templates by default, no admin panel and no built-in project layout; it is a thin routing and middleware layer, which is exactly what many APIs need.
Key takeaways
- Express is a minimal web framework for Node.js, first released in 2010.
- Routes map HTTP methods and paths to handler functions.
- Middleware functions process each request in order and call next().
- It leaves project structure, validation and database access to you.
- NestJS, Fastify and Hono are popular alternatives built on similar ideas.
Example
import express from "express";
const app = express();
app.use(express.json()); // middleware: parse JSON bodies
app.use((req, res, next) => { // middleware: log every request
console.log(req.method, req.path);
next();
});
const books = [{ id: 1, title: "Dune" }];
app.get("/books/:id", (req, res) => {
const book = books.find((b) => b.id === Number(req.params.id));
if (!book) return res.status(404).json({ error: "Not found" });
res.json(book);
});
app.post("/books", (req, res) => {
const book = { id: books.length + 1, title: req.body.title };
books.push(book);
res.status(201).json(book);
});
app.listen(3000);Readers ask
Is Express a backend framework?
Yes. Express runs on the server with Node.js and is used to build APIs and web servers. It is minimal, so it is often called a micro-framework.
What is middleware in Express?
A function that receives the request, the response and a next function. It can modify them, end the request with a response, or pass control to the next middleware or route.
Express or NestJS?
Express is lightweight and flexible, good for small services and quick APIs. NestJS adds a strict structure with modules, dependency injection and decorators, which helps large teams keep big codebases consistent. NestJS can even run on top of Express.
See also
- Node.jsBackend & APIs, p. 32Node.js is an open-source JavaScript runtime that runs JavaScript outside the browser, most often to build web servers, APIs, and command-line tools.
- MiddlewareBackend & APIs, p. 30Middleware is software that sits between two layers of a system, most often code that runs between an incoming request and the final response in a web server.
- REST APIBackend & APIs, p. 38A REST API is a web API that exposes data as resources identified by URLs and lets clients read or change them using standard HTTP methods.
- APIBackend & APIs, p. 2An API is a set of rules that lets one piece of software request data or actions from another in a predictable, documented way.
- Web ServerBackend & APIs, p. 46A web server is software, or the machine running it, that accepts HTTP requests from browsers and other clients and responds with pages, files, or data.
- JavaScriptWeb Development, p. 24JavaScript is the programming language that runs in web browsers to make pages interactive, and it also runs on servers through runtimes like Node.js.
Spotted a mistake or something missing on this page?Suggest an edit