What does Express add over the built-in http module?
3 minbeginnernodejsexpresshttpframeworkmiddleware
Quick Answer
The http module is a low-level primitive: you manually parse URLs, methods, and bodies and write raw responses. Express adds routing, a middleware pipeline, request/response helpers (res.json, req.params/query/body), view/static support, and a large ecosystem — dramatically less boilerplate for building APIs.
Detailed Answer
Answer:
Raw http module — everything is manual:
const http = require('http');
http.createServer((req, res) => {
if (req.method === 'GET' && req.url === '/users') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(users));
} else {
res.writeHead(404);
res.end('Not found');
}
}).listen(3000);
You hand-roll routing, method checks, body parsing, headers, and content types.
Express — a thin framework over http:
const express = require('express');
const app = express();
app.use(express.json()); // body parsing
app.get('/users', (req, res) => res.json(users));
app.get('/users/:id', (req, res) => res.json(findUser(req.params.id)));
app.listen(3000);
What Express provides:
- Routing — match method + path patterns, with params (
/users/:id) and routers for modular structure. - Middleware pipeline — compose cross-cutting concerns (logging, auth, parsing, CORS).
- Request/response helpers —
req.params,req.query,req.body,res.json(),res.status(),res.redirect(). - Static files & views, and a huge middleware ecosystem (helmet, morgan, multer, ...).
Interview point: Express doesn't replace http — it wraps it, giving structure and convenience while still ultimately using the same server. Alternatives (Fastify, Koa, NestJS) make different trade-offs around performance, async design, and structure.