npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@philiprehberger/healthcheck

v0.2.1

Published

Production readiness health check builder with typed check results

Readme

@philiprehberger/healthcheck

CI npm version Last updated

Production readiness health check builder with typed check results

Installation

npm install @philiprehberger/healthcheck

Usage

import { createHealthcheck, check } from '@philiprehberger/healthcheck';

const health = createHealthcheck([
  check('database', async () => { await db.ping(); }),
  check('redis', async () => { await redis.ping(); }),
  check('api', async () => {
    const res = await fetch('https://api.example.com/health');
    if (!res.ok) throw new Error(`Status ${res.status}`);
  }),
]);

// Express/Fastify handler
app.get('/health', async (req, res) => {
  const result = await health();
  res.status(result.status === 'healthy' ? 200 : 503).json(result);
});

Check Dependencies

Use dependsOn to ensure a check only runs after its dependencies pass. If a dependency fails, the dependent check is automatically marked unhealthy.

import { createHealthcheck, check } from '@philiprehberger/healthcheck';

const health = createHealthcheck([
  check('database', async () => { await db.ping(); }),
  check('migrations', async () => { await db.checkMigrations(); }, {
    dependsOn: ['database'],
  }),
  check('seed-data', async () => { await db.checkSeeds(); }, {
    dependsOn: ['database', 'migrations'],
  }),
]);

Degraded Status

Configure a threshold to distinguish between "degraded" and "unhealthy". When the percentage of passing checks is at or above the threshold, the overall status is "degraded" instead of "unhealthy".

import { createHealthcheck, check } from '@philiprehberger/healthcheck';

const health = createHealthcheck(
  [
    check('database', async () => { await db.ping(); }),
    check('redis', async () => { await redis.ping(); }),
    check('cdn', async () => { await cdn.ping(); }),
    check('search', async () => { await search.ping(); }),
  ],
  { degradedThreshold: 50 },
);

// If 3 of 4 pass (75%) -> "degraded" (above 50% threshold)
// If 1 of 4 pass (25%) -> "unhealthy" (below 50% threshold)
// If 4 of 4 pass (100%) -> "healthy"

Check Grouping

Organize checks into named groups for structured health reports. Each group gets its own aggregated status.

import { createHealthcheck, check, group } from '@philiprehberger/healthcheck';

const health = createHealthcheck([
  ...group('database', [
    check('postgres', async () => { await pg.ping(); }),
    check('migrations', async () => { await pg.checkMigrations(); }),
  ]),
  ...group('cache', [
    check('redis', async () => { await redis.ping(); }),
    check('memcached', async () => { await memcached.ping(); }),
  ]),
  ...group('external', [
    check('stripe', async () => { await stripe.ping(); }),
    check('sendgrid', async () => { await sendgrid.ping(); }),
  ]),
]);

const result = await health();
// result.groups['database'].status => 'healthy'
// result.groups['cache'].checks['redis'].status => 'healthy'

Per-Check Timeout

Set a timeout per check in milliseconds. If the check does not complete within the timeout, it is marked unhealthy with a timeout error.

import { createHealthcheck, check } from '@philiprehberger/healthcheck';

const health = createHealthcheck([
  check('database', async () => { await db.ping(); }, { timeout: 3000 }),
  check('external-api', async () => {
    const res = await fetch('https://slow-api.example.com/health');
    if (!res.ok) throw new Error(`Status ${res.status}`);
  }, { timeout: 5000 }),
]);

Response

{
  "status": "healthy",
  "checks": {
    "database": { "status": "healthy", "duration": 12 },
    "redis": { "status": "healthy", "duration": 3 },
    "api": { "status": "healthy", "duration": 45 }
  },
  "timestamp": "2026-03-13T10:00:00.000Z"
}

API

| Export | Description | |--------|-------------| | createHealthcheck(checks, config?) | Returns async function that runs all checks, respecting dependencies | | check(name, fn, options?) | Define a named health check with optional configuration | | group(name, checks) | Assign a group name to an array of checks |

CheckOptions

| Property | Type | Description | |----------|------|-------------| | dependsOn | string[] | Names of checks that must pass before this check runs | | timeout | number | Timeout in milliseconds; check fails if exceeded | | group | string | Group name for categorizing this check |

HealthcheckConfig

| Property | Type | Default | Description | |----------|------|---------|-------------| | degradedThreshold | number | 50 | Percentage (0-100) of checks that must pass for "degraded" instead of "unhealthy" |

HealthResult

| Property | Type | Description | |----------|------|-------------| | status | 'healthy' \| 'degraded' \| 'unhealthy' | Overall status | | checks | Record<string, CheckResult> | Per-check results | | groups | Record<string, GroupResult> | Per-group aggregated results (present when groups are used) | | timestamp | string | ISO timestamp |

CheckResult

| Property | Type | Description | |----------|------|-------------| | status | 'healthy' \| 'degraded' \| 'unhealthy' | Check status | | duration | number | Execution time in milliseconds | | error | string | Error message (when unhealthy) | | group | string | Group name (when assigned) |

GroupResult

| Property | Type | Description | |----------|------|-------------| | status | 'healthy' \| 'degraded' \| 'unhealthy' | Aggregated group status | | checks | Record<string, CheckResult> | Checks belonging to this group |

Development

npm install
npm run build
npm test

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT