Express.js Framework
- Express
- Node.js
- HTTP
A minimal, unopinionated web framework for Node.js that turns incoming HTTP requests into responses through a chain of routes and middleware.
Prerequisites
- Node.js runtime basics and HTTP request/response basics (see Related Topics)
What you'll understand
- What Express is and the problem it solves for Node servers
- How an Express app turns a request into a response
- Why Express is described as minimal and unopinionated
Explanation
Express is a small, widely used web framework for Node.js. Node can create an HTTP server on its own, but doing so means parsing URLs, matching methods, and handling bodies by hand. Express provides a thin, comfortable layer over that: you declare routes and it dispatches each request to the right handler.
An Express application is essentially a pipeline. A request enters, passes through a series of functions, and one of them sends a response. Those functions are either middleware (which can inspect or modify the request and pass it on) or route handlers (which match a specific method and path and produce the response). This request-response pipeline is the mental model that makes everything else in Express click.
Express is deliberately minimal and unopinionated: it does not dictate your project structure, database, or validation library. That flexibility is a strength for learning and for small services, and it means the conventions, folder layout, error handling, and so on, are yours to establish. Larger frameworks build on these same ideas with more structure.
Examples
This TypeScript example creates an Express app, defines one route, and starts listening:
import express from 'express';
const app = express();
app.use(express.json()); // parse JSON request bodies
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
app.listen(3000, () => {
console.log('listening on http://localhost:3000');
});A request to GET /health flows through the JSON middleware, matches the route, and receives a JSON response.
Common mistakes
- Forgetting to send a response, so the request hangs until it times out.
- Registering middleware after the route that needs it; order matters in the pipeline.
- Not adding a body parser (such as express.json()) and then finding req.body undefined.
- Treating Express as if it enforces structure; you must impose your own conventions.
Best practices
- Keep route handlers thin and move real logic into separate functions (see Related Topics).
- Register shared middleware before the routes that rely on it.
- Always end each request with exactly one response or a call to next().
- Add a central error handler so failures return consistent responses.
Further reading
- Express, Hello world example — https://expressjs.com/en/starter/hello-world.html
- Express, Official website — https://expressjs.com/