1.0.0 • Published 11 months ago
@merncloud/health-service v1.0.0
@merncloud/health-service
A simple and extensible health checker for monitoring services (MySQL, MongoDB, Redis, etc.) in Node.js apps.
🚀 Features
- Plug in your own service checks
- Returns a health score (e.g.,
5.31) - Lists failed services
- Framework-agnostic — works with Express, NestJS, etc.
📦 Installation
npm install @merncloud/health-serviceUsage
import { HealthChecker } from "@merncloud/health-service";
const checker = new HealthChecker([
{ name: "mysql", check: async () => isMySQLConnected() },
{ name: "redis", check: async () => pingRedis() },
{ name: "swagger", check: async () => checkSwaggerStatus() },
]);
const report = await checker.checkHealth();
console.log(report);
/*
{
statusCode: 200,
healthScore: 5.31,
failedServices: ['swagger']
}
*/Define your checks
// Each service must return a Promise<boolean>
const isMySQLConnected = async (): Promise<boolean> => {
try {
await mysqlClient.ping();
return true;
} catch {
return false;
}
};Create health check route
@Get('/metrics')
async getMetrics(@Res() res: Response) {
const report = await checker.checkHealth();
res.status(report.statusCode).json(report);
}1.0.0
11 months ago