Skip to content

Repository files navigation

Express Template

A production-shaped Express + TypeScript starting point: request correlation, structured logging, validated configuration, i18n, rate limiting, Prometheus metrics, a uniform error contract, Docker and PM2 — wired together and working.

📚 Full documentation → docs/ — architecture, security, performance, deployment and a guide to extending the template. Using an AI assistant? Point it at CLAUDE.md.

Getting started

Prerequisites — Node.js ≥ 18.18 and Git. TypeScript is a project dependency; you do not need it globally. The project uses npm — package-lock.json is committed and CI installs with npm ci.

git clone git@github.com:suman7802/ExpressTemplate.git
cd ExpressTemplate
npm install

npm run setup                  # creates .env.local with a generated API_KEY
npm run dev

Open http://localhost:8080 — you should get the welcome envelope, and http://localhost:8080/docs for the interactive API reference.

The server validates its configuration at boot and refuses to start if anything is missing, and tells you exactly what. That is a feature; see docs/04-configuration.md.

For production: npm run build then npm start.

Detailed walkthrough: docs/01-getting-started.md

Scripts

Command Purpose
npm run setup Create .env.local with a generated API_KEY
npm run dev Watch mode with hot restart (dev:debug for the inspector)
npm run build tsc + rewrite @/ path aliases (rebuild for a clean build)
npm start Run the compiled build in production mode
npm run check typecheck + lint + format:check — what CI runs
npm run fix ESLint --fix + Prettier
npm run pm2:prod Build, then start under PM2 cluster mode
npm run docker:up Start the API + Prometheus + Grafana stack

Full list: docs/01-getting-started.md

Documentation

Postman Collection

The docs/ folder explains how the server works and why it is built this way — aimed at engineers who want more than a list of npm packages:

Architecture The middleware pipeline, layers, request lifecycle
Project structure What every file is for
Configuration Env vars, validated and typed at boot
Validation Zod at the edge, types inferred from schemas
Error handling One error contract for the whole API
Security Every defence, every gap, a production checklist
Performance The event loop, clustering, measuring
Observability Metrics, health checks, Grafana
Deployment Docker, PM2, reverse proxies, zero-downtime
Extending Adding features, a database, auth, tests
Troubleshooting Symptoms → causes → fixes

Docker compose

Runs the API alongside Prometheus and Grafana:

npm run setup -- .env.production   # generates an API_KEY; review the rest
npm run docker:up
Service URL
API http://localhost:8080
Prometheus http://localhost:9090
Grafana http://localhost:3001 (admin / admin)

Features

Request handling — versioned routing · zod validation with inferred types · uniform success and error envelopes · async error propagation · request ids echoed as Request-Id

API reference — interactive /docs page with a try-it console, generated from the same zod schemas that validate requests · OpenAPI 3.0 spec at /docs/openapi.json · one env flag, one folder, trivially removable

Security — helmet · CORS allow-list · rate limiting · progressive throttling · constant-time API key checks · body size limits · upload type/size/count limits · proxy-aware client IPs · no stack traces in production

Observability — Winston (JSON, levelled, rotated) · Morgan piped into Winston · Prometheus histograms and counters with bounded labels · health endpoint · containerised Grafana

Operations — boot-time config validation · graceful shutdown with a forced timeout · PM2 cluster mode · multi-stage non-root Docker image · GitHub Actions CI

Content — i18n (English + Nepali, typed keys) · SendGrid email with local Handlebars templates

Roadmap

  • Automated tests (Vitest + supertest — see docs/17)
  • Authentication and authorization
  • Database layer
  • Grafana Loki for logs
  • Redis-backed rate limiting for multi-process deployments

Contributing

Contributors are welcome.

  1. Fork the repository
  2. git checkout -b feature/new-feature
  3. Make your changes — npm run typecheck && npm run lint must pass
  4. git commit -m "feat: add new feature"
  5. git push origin feature/new-feature
  6. Open a Pull Request

Please read docs/16-coding-standards.md first.

Contact

License

Licensed under the MIT License. See LICENSE.