How do you create a web server with Node's built-in http module? What does Express add on top of it?
Show the explanation
Model answer. The http module gives you a raw server: one callback per request, with the request and response objects.
import http from 'node:http';
const server = http.createServer((req, res) => {
if (req.method === 'GET' && req.url === '/health') {
res.writeHead(200, { 'Content-Type': 'application/json' });
return res.end(JSON.stringify({ ok: true }));
}
res.writeHead(404); res.end('Not found');
});
server.listen(3000);You must parse URLs and bodies yourself, set headers manually, and write your own routing with if statements.
Express is a thin framework on top of http that adds:
- Routing by method and path, with parameters (
app.get('/users/:id', ...)). - Middleware: a chain for logging, parsing JSON bodies, authentication, CORS and error handling.
- Response helpers:
res.json(),res.status(),res.redirect(),res.sendFile(). - Serving static files with
express.static.
Express does not replace Node; it organises the same request/response flow so large APIs stay maintainable.
Original UniCircle question. Last reviewed 22 Oct 2026.
