What Is Express
Express is a minimal, unopinionated web framework for Node.js. It sits on top of Node’s built-in http module and adds routing, middleware, and a cleaner request/response API — the things you need to build any web server.
Node.js without Express
Section titled “Node.js without Express”Node.js has a built-in http module. You can create a server without any framework:
import { createServer } from 'http'
const server = createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }) res.end(JSON.stringify({ message: 'hello' }))})
server.listen(3000)This works, but it’s very low-level. You manually parse URLs, check HTTP methods, set headers, and serialize JSON for every single route. With 20 routes, this becomes unmanageable.
What Express adds
Section titled “What Express adds”Express wraps the http module with:
- Routing — match specific URL patterns and HTTP methods to handler functions
- Middleware — a pipeline of functions that process requests before they reach route handlers
- Request helpers —
req.params,req.query,req.bodyparsed automatically - Response helpers —
res.json(),res.status(),res.send()that handle headers for you
Installing Express
Section titled “Installing Express”npm install expressnpm install --save-dev @types/expressHello world
Section titled “Hello world”import 'dotenv/config'import express from 'express'import { config } from './config.js'
const app = express()
app.get('/', (req, res) => { res.json({ message: 'Bulletin API' })})
app.listen(config.port, () => { console.log(`API running on http://localhost:${config.port}`)})Run it:
npm run devVisit http://localhost:3000 — you see {"message":"Bulletin API"}.
The Express application
Section titled “The Express application”express() creates an application instance — app. It’s the central object you:
- Register middleware on:
app.use(middleware) - Define routes on:
app.get('/path', handler) - Start the HTTP server with:
app.listen(port, callback)
Route handlers
Section titled “Route handlers”A route handler is a function that receives the request (req) and response (res):
app.get('/health', (req, res) => { res.json({ status: 'ok', uptime: process.uptime() })})The handler should always send a response — either with res.json(), res.send(), res.status().json(), or by passing to the next middleware with next().
Express vs other frameworks
Section titled “Express vs other frameworks”Express is minimal by design — it doesn’t make choices about database libraries, authentication, or project structure. You assemble the stack yourself. Alternatives like Fastify, Hapi, or NestJS are more opinionated, but Express remains the most widely used Node.js framework and what you’ll encounter in most existing codebases.
Exercise
Section titled “Exercise”- Install Express and
@types/expressin yourbulletin-apiproject. - Create
src/index.tswith the hello world example above. - Add a second route:
GET /healththat returns{ status: 'ok' }. - Run the server and test both routes in your browser.
- Node.js’s built-in
httpmodule is low-level; Express wraps it with routing and middleware. express()creates an app;app.listen(port)starts the server.- Route handlers receive
reqandresand must always send a response. - Express is minimal and unopinionated — you choose the rest of your stack.