Skip to main content

Express (Node.js)

Overview

Express is a minimal, unopinionated Node.js web framework for HTTP APIs and server-rendered sites. Its middleware model makes it easy to compose auth, logging, compression, and error handling—often paired with databases and front-end SPAs.

Key concepts

  • Middleware — Functions (req, res, next) chained in order.
  • Router — Modular route tables for larger apps.
  • Template engines — Optional (Pug, EJS) for HTML.
  • Error handling — Centralized 4-arg error middleware.
  • Security — Use helmet, rate limits, and validated parsers in production.

Middleware pipeline

Sample: JSON API

import express from 'express';

const app = express();
app.use(express.json());

app.get('/api/health', (_req, res) => {
res.json({ ok: true });
});

app.listen(3000);

References