Express example
The apps/example-express directory contains a working Express 5 API that
wires every @rtorcato/api-* package together so you can see how they
interact in a real server.
What it demonstrates
| Package | Usage in the example |
|---|---|
api-config | loadEnv() validates PORT + LOG_LEVEL from .env at startup |
api-logger | createLogger() gives a pino logger, pretty-printed in dev |
api-errors | NotFoundError is thrown when an item ID doesn't exist |
api-errors-express | errorHandler() + notFoundHandler convert those errors to JSON |
api-express-utils | getIP() keys the rate limiter; logRoutes() prints routes on start |
api-rate-limit | createRateLimiter() — 100 req/min sliding window, in-memory |
api-response | ok() wraps every success payload in { success: true, data } |
api-validation | validate() parses POST bodies and throws BadRequestError on failure |
api-openapi | OpenAPI spec defined in src/spec.ts; generateScalarHtml / generateSwaggerHtml render the UI pages |
api-openapi-express | serveApiDocs() mounts Scalar UI at /api-docs; serveSwaggerDocs() mounts Swagger UI at /swagger |
Routes
GET /items
POST /items { "name": string }
GET /items/:id
DELETE /items/:id
GET /api-docs Scalar API reference
GET /api-docs/openapi.json
GET /swagger Swagger UI
GET /swagger/openapi.json
Items are stored in-memory — no database required.
Run locally
cd apps/example-express
cp .env.example .env
pnpm dev
The server starts on http://localhost:3001 with pretty-printed logs.
- Scalar API reference →
http://localhost:3001/api-docs - Swagger UI →
http://localhost:3001/swagger
Run with Docker
cd apps/example-express
docker compose up
The image builds from the monorepo root, installs workspace packages, and
starts the server on port 3001.
Quick smoke test
# List items (empty)
curl http://localhost:3001/items
# Create
curl -X POST http://localhost:3001/items \
-H 'Content-Type: application/json' \
-d '{"name":"hello"}'
# 404 for a bad ID
curl http://localhost:3001/items/bad-id
# 400 validation error — missing name
curl -X POST http://localhost:3001/items \
-H 'Content-Type: application/json' \
-d '{}'