Health Check
The Health Check component provides production-ready endpoints for monitoring your API's status, system health, and service availability. Essential for load balancers, monitoring systems, and deployment tools.
Features
- Basic health check - Simple endpoint to verify service is running
- Detailed health check - System information including memory, CPU, and uptime
- Database connectivity check - Optional database health verification
- Customizable - Easy to extend with additional health checks
- Production-ready - Standardized responses for monitoring tools
Installation Guide
This component requires additional Servercn components.
👉 You do not need to install any Servercn components manually. Running this component installer will automatically install all required components. Manual installation is optional and only recommended if you prefer fine-grained components control
1. Install Servercn components(Optional)
2. Install this component
npx servercn-cli add health-checkBasic Implementation
1. MVC Structure
Create health check controller in src/controllers/health.controller.ts:
Create routes in src/routes/health.routes.ts:
2. Feature Structure
For feature-based architecture, place controller in src/modules/health/health.controller.ts:
Usage Examples
1. Basic Health Check
Simple endpoint that returns service status:
Response:
2. Detailed Health Check
Include system information:
Response:
Route Setup
src/routes/health.routes.ts
src/app.ts
Security Considerations
- Rate limiting - Consider rate limiting health check endpoints
- Authentication - Optionally protect detailed endpoints
- IP whitelisting - Restrict access to monitoring IPs if needed
- Information disclosure - Don't expose sensitive system information
Common Use Cases
- Load balancer health checks - Verify service availability
- Monitoring systems - Track service uptime and performance
- Deployment verification - Confirm successful deployments
- Auto-scaling - Determine when to scale services
- Incident response - Quick status verification during outages