A production-ready API boilerplate using Express.js and TypeScript, featuring robust validation, error handling, logging, and monitoring.
- Node.js 22+ - Latest LTS version
- TypeScript - Modern JavaScript with type safety
- Express.js - Fast, unopinionated web framework
- PostgreSQL - Scalable, relational database
- Knex.js - SQL query builder with migrations
- Helmet - Secure HTTP headers
- CORS - Cross-Origin Resource Sharing
- Rate Limiting - Throttling API requests
- Zod Validation - Input validation and schema enforcement
- Strict TypeScript Configuration - Type safety enforcement
- Route-specific validation schemas
- Custom validation rules per endpoint
- Centralized error handling with detailed responses
- Type-safe request validation
- Sentry - Error tracking and performance monitoring
- Better Stack - Advanced logging and monitoring
- Pino - High-performance structured logging
- Environment-based log levels
- ESLint - Code linting with custom rules
- Prettier - Code formatting
- Jest - Testing framework
- Husky - Git hooks for CI/CD
- Docker - Containerized deployment
- Docker Compose - Multi-container orchestration
Ensure you have the following installed:
- Node.js 22+
- PostgreSQL 16+
- Redis 7+
- Docker & Docker Compose (optional)
Copy .env.example
to .env
and configure:
NODE_ENV=development
PORT=3000
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/express_ts_db
REDIS_URL=redis://localhost:6379
SENTRY_DSN=your-sentry-dsn
BETTER_STACK_TOKEN=your-betterstack-token
-
Clone the repository:
git clone <repository-url> cd express-typescript-api-boilerplate
-
Install dependencies:
npm install
-
Run database migrations:
npm run migrate
npm run dev
npm run build
npm start
docker-compose up -d
Each route has a validation schema in src/validations
:
export const createUserSchema = z.object({
body: z.object({
name: nameSchema,
email: emailSchema,
role: z.enum(['user', 'admin']),
}),
});
The validate
middleware enforces schema validation:
router.post('/', validate(createUserSchema), userController.createUser);
- Custom error classes
- Centralized error responses
- Sentry error tracking
- Development/production error details
- Performance monitoring
- Error tracking
- Request tracing
- Node.js profiling
- Structured logging
- Log aggregation
- Production monitoring
- Custom log transport
Run tests:
npm test # Run all tests
npm run test:watch # Watch mode
npm run lint # Check linting
npm run lint:fix # Auto-fix linting issues
npm run typecheck
npm run migrate:make migration_name # Create a new migration
npm run migrate # Apply migrations
npm run seed:make seed_name # Create a new seed
npm run seed # Run seeds
src/
├── config/ # Configuration files
├── controllers/ # Route controllers
├── database/ # Migrations and seeds
├── middlewares/ # Express middlewares
├── models/ # Data models
├── routes/ # API route definitions
├── services/ # Business logic
├── types/ # TypeScript type definitions
├── utils/ # Utility functions
└── validations/ # Request validation schemas
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Submit a Pull Request
This project is licensed under the MIT License - see the LICENSE
file for details.