|
| 1 | +# Production Node.js API Starter |
| 2 | + |
| 3 | +[](https://github.com/ManikandaMkM/node-production-api-starter/actions/workflows/ci.yml) |
| 4 | +[](https://nodejs.org/) |
| 5 | +[](LICENSE) |
| 6 | + |
| 7 | +A deliberately small Express 5 starter demonstrating production concerns often missing from hello-world APIs: validated configuration, structured logging, request IDs, secure defaults, consistent errors, health probes, graceful shutdown, tests, CI, and a non-root container. |
| 8 | + |
| 9 | +## Quick start |
| 10 | + |
| 11 | +```bash |
| 12 | +cp .env.example .env |
| 13 | +npm install |
| 14 | +npm run dev |
| 15 | +``` |
| 16 | + |
| 17 | +```bash |
| 18 | +curl http://localhost:3000/health/ready |
| 19 | +curl -X POST http://localhost:3000/api/v1/echo \ |
| 20 | + -H 'content-type: application/json' \ |
| 21 | + -d '{"message":"hello"}' |
| 22 | +``` |
| 23 | + |
| 24 | +## Included patterns |
| 25 | + |
| 26 | +- Express 5 with versioned routes |
| 27 | +- Zod environment and request validation |
| 28 | +- Helmet security headers and disabled framework fingerprinting |
| 29 | +- JSON logs with sensitive-header redaction |
| 30 | +- Request correlation through `x-request-id` |
| 31 | +- Stable error envelopes that avoid leaking internals |
| 32 | +- Separate liveness and readiness endpoints |
| 33 | +- Bounded JSON bodies and configurable proxy trust |
| 34 | +- Graceful `SIGTERM`/`SIGINT` shutdown |
| 35 | +- Vitest and Supertest coverage |
| 36 | +- Least-privilege container runtime |
| 37 | +- Dependency-cached GitHub Actions CI |
| 38 | + |
| 39 | +## Response shape |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "error": { |
| 44 | + "code": "VALIDATION_ERROR", |
| 45 | + "message": "Request body is invalid", |
| 46 | + "requestId": "d36760ab-5a5d-45e3-aaf7-0c58ad6d020e" |
| 47 | + } |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +## Production checklist |
| 52 | + |
| 53 | +This starter provides foundations, not a universal security claim. Before launch, add authentication and authorization for your domain, datastore readiness checks, rate limiting at the edge, CORS rules, secret management, observability export, backups, dependency scanning, and a deployment-specific rollback plan. |
| 54 | + |
| 55 | +## Design principles |
| 56 | + |
| 57 | +1. Fail fast when configuration is invalid. |
| 58 | +2. Make every request traceable without logging secrets. |
| 59 | +3. Keep operational probes independent from business routes. |
| 60 | +4. Return useful client errors and private server errors. |
| 61 | +5. Make shutdown behavior explicit and testable. |
| 62 | + |
| 63 | +Built as a public engineering reference by [Manikandan Menon](https://github.com/ManikandaMkM). |
0 commit comments