Skip to content

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 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.

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 helpersreq.params, req.query, req.body parsed automatically
  • Response helpersres.json(), res.status(), res.send() that handle headers for you
Terminal window
npm install express
npm install --save-dev @types/express
src/index.ts
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:

Terminal window
npm run dev

Visit http://localhost:3000 — you see {"message":"Bulletin API"}.

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)

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 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.

  1. Install Express and @types/express in your bulletin-api project.
  2. Create src/index.ts with the hello world example above.
  3. Add a second route: GET /health that returns { status: 'ok' }.
  4. Run the server and test both routes in your browser.
  • Node.js’s built-in http module is low-level; Express wraps it with routing and middleware.
  • express() creates an app; app.listen(port) starts the server.
  • Route handlers receive req and res and must always send a response.
  • Express is minimal and unopinionated — you choose the rest of your stack.