Express.js
A web framework for Node.js that sends incoming HTTP requests to the right functions and helps those functions return a response. It is used to build APIs and websites.
Also known as: Express, NestJS
What Express does
Express.js, usually called Express, sits on top of Node.js's HTTP support. Node.js runs the JavaScript and provides the underlying server capabilities. Express lets you declare what should happen for a request such as GET /books/42 instead of writing the request-matching logic yourself.
Express is not another name for NestJS. NestJS is a separate framework that provides its own application structure, including modules and dependency injection. It uses Express as its default HTTP adapter, but can use Fastify instead.
How a request moves through the app
An Express app is an ordered stack of routes and middleware. A route registered with app.get() matches a GET request to a particular path. Middleware registered with app.use() can run for multiple methods and routes, optionally under a path prefix. That makes it useful for shared work such as request logging or parsing a request body.
A handler reads incoming data from req and uses res to build and send the response. For example, the 42 in /books/42 is available as req.params.id if the route is defined as /books/:id. The 2 in /books?page=2 comes from req.query.page. A middleware function can respond immediately or call next() to let the next matching handler run. If it does neither, the request is left waiting.
Example: a JSON endpoint
const express = require('express');
const app = express();
app.get('/books/:id', (req, res) => {
if (req.params.id !== '42') {
return res.status(404).json({ error: 'Book not found' });
}
res.json({ id: 42, title: 'The Hobbit' });
});
app.listen(3000);
GET /books/42 returns a JSON object with status 200. A request for /books/99 matches the same route, but the handler sends 404 because that book doesn't exist in this example. res.json() sends the response; the early return stops the function from trying to send another one.
Where it fits and what to watch for
Express is used for JSON APIs, webhook receivers, and websites that serve static files or render HTML. It does not prescribe a project layout, database layer, or input validation strategy. For example, express.json() parses JSON request bodies when the content type matches, but it does not check that a required field is present. Register it before any route that needs to read the parsed body from req.body.
What interviewers ask
A typical question is how a failing handler reaches a central error handler. next() continues normal processing; next(err) skips ordinary handlers and looks for error-handling middleware, identified by its four parameters: (err, req, res, next). Register that middleware after the routes it should handle. Version matters: Express 5 automatically forwards rejections from promises returned by handlers, whereas Express 4 requires explicit forwarding, for example with .catch(next).