Introduction
Express is the most popular web framework for Node.js, and it is deliberately tiny: a minimal layer on top of Node's built-in HTTP handling that adds routing and middleware, and little else. Where Django and Laravel include everything, Express includes almost nothing — and that minimalism is exactly why it powers so many APIs: you add only what your project needs.
Routes: five lines to an API
An Express application is a list of routes — URL patterns paired with handler functions:
const express = require("express");
const app = express();
app.use(express.json());
app.get("/posts", (req, res) => {
res.json(posts);
});
app.post("/posts", (req, res) => {
const post = { id: posts.length + 1, ...req.body };
posts.push(post);
res.status(201).json(post);
});
app.listen(3000, () => console.log("Server running on port 3000"));
app.get handles reads, app.post handles submissions, express.json() parses incoming JSON bodies, and res.json sends JSON back. That is a working API in under twenty lines — the reason Express is the first framework most Node developers learn.
Middleware: the conveyor belt idea
Express's central concept is middleware: functions that run in sequence for each request, each able to inspect it, modify it, or stop it. Authentication, logging, and error handling are all middleware:
// Logging middleware: runs for every request, then passes on
app.use((req, res, next) => {
console.log(`${req.method} ${req.url}`);
next();
});
// Authentication middleware: stops unauthenticated requests
function requireLogin(req, res, next) {
if (!req.headers.authorization) {
return res.status(401).json({ error: "Login required" });
}
next();
}
app.get("/private", requireLogin, (req, res) => {
res.json({ secret: "Only for logged-in users" });
});
next() is the key: call it to pass the request along, or don't — and the request stops there. Once you understand this conveyor belt, Express's entire ecosystem (thousands of middleware packages) makes sense: each one is just a step on the belt.
The honest trade
Express's minimalism has a cost: authentication, validation, database access, and structure are all your responsibility, chosen from the ecosystem. Two Express applications can look completely different, and beginners can feel lost without the guardrails Django or Laravel provide. But that same freedom is why Express fits APIs, microservices, and prototypes so well — it gets out of the way, and stays out of the way.
Takeaway
Routes as a readable list, middleware as a conveyor belt of request handlers, and a framework small enough to learn in a day. Express is minimal on purpose — and for a JavaScript API, minimal is often exactly right.
Originally published at https://practicaldevblog.blogspot.com/2026/10/express-explained-nodes-minimal-web.html
Top comments (0)