A minimal Node.js boilerplate for building backend APIs with clean architecture.
npm installcp .env.example .env.development
cp .env.example .env.qa
cp .env.example .env.staging
cp .env.example .env.productionEdit each file with your configuration values. See .env.example for available options.
npm run dev # Development (auto-reload)
npm run qa # QA environment
npm run staging # Staging environment
npm start # ProductionServer runs at http://localhost:5000
src/
├── config/ Configuration & environment
├── constants/ App constants
├── controllers/ Request handlers
├── database/ Database connection
├── middleware/ Express middleware (logging, error handling, security)
├── models/ Database schemas
├── routes/ API route definitions
├── services/ Business logic
├── utils/ Utility functions
├── validators/ Input validation
└── server.js Express app setup
| Endpoint | Method | Purpose |
|---|---|---|
/health |
GET | Health check |
/info |
GET | API info |
/api/db/status |
GET | Database status |
npm start Production server
npm run dev Dev server (auto-reload)
npm run qa QA environment
npm run staging Staging environment
npm run lint ESLint check
npm run lint:fix Fix linting issues
npm run format Format code
npm run build Lint + format
npm test Run tests
npm run test:watch Watch mode tests
npm run test:coverage Coverage reportAll configuration via environment variables. See .env.example.
Key variables:
APP_ENV- Environment typeAPP_PORT- Server portLOG_LEVEL- Logging levelDB_TYPE- Database type (mongodb|mysql|postgresql)CORS_ORIGIN- CORS origins
npm test Run tests
npm run test:watch Watch mode
npm run test:coverage CoverageTest files in src/__tests__/:
- Unit tests for database & controllers
- Integration tests for API endpoints
Husky runs ESLint & Prettier before commits:
git commit -m "message" Runs hooks automatically
git commit --no-verify Skip hooks if needed- Create
src/validators/yourValidator.js - Use in controllers
- Create
src/models/YourModel.js - Use in services
- Create
src/services/YourService.js - Import in controllers
- Use for database operations & business logic
- Create
src/controllers/YourController.js - Create
src/routes/yourRoutes.js - Mount in
src/server.js