Skip to main content
Health checks give your infrastructure — load balancers, container orchestrators, and on-call engineers — an instant answer to “is this service ready to receive traffic?” The @figentra/health package provides a composable, typed health check system that aggregates the status of your database, cache, external APIs, and any other dependency into a single /health endpoint. When every Figentra service uses the same package, your monitoring dashboards and runbooks stay consistent across the entire platform.

Installation

Quick Start

1

Import createHealthCheck

Import createHealthCheck from @figentra/health at the top of your server entry point.
2

Define your health checks

Create an array of named checks. Each check is an async function that resolves to a HealthCheckResult. Return status: 'healthy' on success and status: 'unhealthy' with a descriptive message on failure.
3

Mount the handler at /health

Pass your checks to createHealthCheck and mount the returned handler on your HTTP server.

API Reference

createHealthCheck(checks)

Creates a health check request handler that runs all provided checks in parallel and aggregates the results.
HealthCheck[]
required
An array of health check definitions. All checks run concurrently. If any single check throws or returns status: 'unhealthy', the overall response status becomes 'unhealthy' and the HTTP status code becomes 503.
Returns a framework-agnostic handler function with the signature (req, res) => Promise<void>. Adapters for Hono, Express, and Fastify are available as named exports (see the complete example below).

HealthCheck type

Describes a single check that the handler will run.
string
required
A human-readable identifier for this check (e.g. "database", "stripe-api"). Appears verbatim in the response JSON.
() => Promise<HealthCheckResult>
required
An async function that performs the check. It must resolve to a HealthCheckResult. If it throws, the check is recorded as unhealthy with the error message captured automatically.

HealthCheckResult type

The value your check function must return.
'healthy' | 'unhealthy'
required
Whether the dependency is reachable and functioning correctly.
string
An optional human-readable explanation. Recommended when status is 'unhealthy' to surface the root cause without requiring log access.
number
The round-trip time in milliseconds for the check operation. Include this whenever you can measure it — it is surfaced in the response and useful for latency-based alerting.

Example Response

A successful response looks like this:
When one or more checks fail, the top-level status flips to "unhealthy" and the individual check entry carries the reason:
The handler returns HTTP 200 when the overall status is "healthy" and HTTP 503 Service Unavailable when any check is "unhealthy". Configure your load balancer or readiness probe to treat anything other than 200 as out-of-rotation.

Complete Example