typescriptintermediate
Health, Readiness & Liveness Checks
Express routes implementing Kubernetes-style health, readiness, and liveness probe endpoints.
typescriptPress ⌘/Ctrl + Shift + C to copy
import { Router, Request, Response } from 'express';
interface HealthDependency {
name: string;
check: () => Promise<boolean>;
}
export function healthRouter(dependencies: HealthDependency[]) {
const router = Router();
router.get('/healthz', (_req: Request, res: Response) => {
res.json({ status: 'ok', uptime: process.uptime() });
});
router.get('/readyz', async (_req: Request, res: Response) => {
const results = await Promise.all(
dependencies.map(async (dep) => {
try {
const ok = await dep.check();
return { name: dep.name, ok };
} catch {
return { name: dep.name, ok: false };
}
})
);
const allOk = results.every((r) => r.ok);
res.status(allOk ? 200 : 503).json({ ready: allOk, checks: results });
});
return router;
}Use Cases
- Kubernetes deployments
- Load balancer health checks
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
typescriptbeginner
Health Check Endpoint Pattern
Implement comprehensive health checks with dependency status, uptime, and readiness probes.
Best for: Kubernetes liveness probes
#nodejs#health-check
pythonintermediate
Python Logging Configuration
Configure structured logging with handlers, formatters, rotation, and JSON output for production.
Best for: Production-ready structured logging
#python#logging
typescriptintermediate
Health Check Endpoint with Dependency Checks
Express health check endpoint that verifies database, Redis, and disk connectivity with status reporting.
Best for: Kubernetes liveness and readiness probes
#health-check#monitoring
javaintermediate
Health Check — Liveness and Readiness
Implement health check endpoints for liveness and readiness probes with dependency status reporting.
Best for: Kubernetes liveness and readiness probes
#java#health-check