X Enterprises
fastify-xconfig

GET /health

System health check endpoint with memory, CPU, disk, and dependency status.

GET /health

Returns a structured system health report including memory, CPU, disk space, and dependency connectivity. Returns 200 when all checks pass and 503 when any check degrades the server status.

Signature

GET /health

No authentication or parameters required.

Returns

200 OK — healthy

{
  "status": "healthy",
  "timestamp": "2025-01-15T12:00:00.000Z",
  "uptime": 3600,
  "environment": "production",
  "dependencies": {
    "database": "up",
    "redis": "not configured"
  },
  "resources": {
    "memory": {
      "rss": "50 MB",
      "heapTotal": "30 MB",
      "heapUsed": "25 MB",
      "external": "2 MB",
      "arrayBuffers": "1 MB"
    },
    "cpu": { "loadAverage": [1.2, 0.8, 0.5], "cpus": 4 },
    "disk": { "free": "100 GB", "size": "500 GB" }
  },
  "details": {}
}

503 Service Unavailable — degraded

{
  "status": "degraded",
  "timestamp": "2025-01-15T12:00:00.000Z",
  "uptime": 3600,
  "environment": "production",
  "dependencies": {
    "database": "down",
    "redis": "not configured"
  },
  "resources": { ... },
  "details": {
    "databaseError": "connect ECONNREFUSED 127.0.0.1:5432"
  }
}

Throws

The route never throws. All dependency checks are wrapped in try/catch; failures set status: "degraded" and populate details.

Degradation conditions

ConditionEffect
Database query (SELECT 1) failsdependencies.database = "down", status → degraded
Redis ping() failsdependencies.redis = "down", status → degraded
DATABASE_URL env var missing when Prisma is activestatus → degraded, details.missingEnvVars populated
Disk space check throwsresources.disk = "unknown", status stays unchanged

Examples

Poll from a load balancer

curl -f http://localhost:3000/health || echo "unhealthy"

Use in automated tests

const response = await fastify.inject({ method: "GET", url: "/health" });
const body = JSON.parse(response.body);

assert.strictEqual(response.statusCode, 200);
assert.strictEqual(body.status, "healthy");
assert.strictEqual(body.dependencies.database, "up");

See also

AI Context

package: "@xenterprises/fastify-xconfig"
route: GET /health
use-when: System health check with memory, CPU, disk, and optional database metrics — registered automatically by xConfig
returns: { status, uptime, memory, cpu, disk, database }
Copyright © 2026