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

health-service

v0.2.0

Published

Health Check

Readme

health-service

A lightweight, framework-independent health check library for Node.js.

health-service provides a simple, extensible way to expose application health endpoints for databases, caches, message queues, external APIs, and other dependencies. It is built on the native Node.js HTTP module and can be used with Express, Fastify, Koa, NestJS, or plain Node.js servers.

Features

  • Lightweight with zero runtime dependencies
  • Framework independent
  • Simple HealthChecker interface
  • Aggregate multiple health checks
  • Hierarchical health status
  • Custom error serialization
  • Native HTTP controller
  • Easy to extend
  • TypeScript support

Installation

npm install health-service

or

yarn add health-service

Examples:


Quick Example

import { createServer } from "http";
import { HealthChecker, HealthController, AnyMap } from "health-service";

class DatabaseChecker implements HealthChecker {
  name(): string {
    return "database";
  }

  async check(): Promise<AnyMap> {
    // verify database connection

    return {
      version: "MySQL 8.0",
      latency: 12
    };
  }

  build(data: AnyMap, err: any): AnyMap {
    return {
      message: err.message
    };
  }
}

const controller = new HealthController([
  new DatabaseChecker()
]);

const server = createServer(controller.check);

server.listen(3000);

Visiting

GET /health

returns

{
  "status": "UP",
  "details": {
    "database": {
      "status": "UP",
      "data": {
        "version": "MySQL 8.0",
        "latency": 12
      }
    }
  }
}

Architecture

                HTTP Request
                      │
                      ▼
              HealthController
                      │
                      ▼
               check(checkers)
                      │
      ┌───────────────┼────────────────┐
      ▼               ▼                ▼
DatabaseChecker   RedisChecker   RabbitMQChecker
      │               │                │
      └───────────────┼────────────────┘
                      ▼
            Combined Health Result
                      │
                      ▼
              JSON HTTP Response

Health Model

The library returns a hierarchical health object.

interface Health {
    status: "UP" | "DOWN";
    data?: AnyMap;
    details?: HealthMap;
}

Example

{
  "status": "DOWN",
  "details": {
    "database": {
      "status": "UP"
    },
    "redis": {
      "status": "DOWN",
      "data": {
        "message": "Connection timeout"
      }
    }
  }
}

Creating a Health Checker

Every component implements the HealthChecker interface.

export interface HealthChecker {
    name(): string;
    check(): Promise<AnyMap>;
    build(data: AnyMap, error: any): AnyMap;
}

name()

Returns the checker name.

name() {
    return "database";
}

The name becomes the key inside details.


check()

Returns application-specific health information.

async check() {
    return {
        version: "8.0",
        latency: 10
    };
}

Throw an exception when the component is unavailable.

async check() {
    throw new Error("Database unavailable");
}

build()

Converts exceptions into JSON.

build(data, err) {
    return {
        message: err.message
    };
}

This allows applications to expose only the information they choose.


Multiple Checkers

Health checks are automatically aggregated.

const controller = new HealthController([
    new DatabaseChecker(),
    new RedisChecker(),
    new RabbitMQChecker()
]);

Result

{
  "status": "UP",
  "details": {
    "database": {
      "status": "UP"
    },
    "redis": {
      "status": "UP"
    },
    "rabbitmq": {
      "status": "UP"
    }
  }
}

If any checker fails, the overall status becomes

{
    "status":"DOWN"
}

while successful checkers still appear in the response.


Supported Use Cases

Health checks can be implemented for

  • MySQL
  • PostgreSQL
  • Oracle
  • SQL Server
  • MongoDB
  • Redis
  • RabbitMQ
  • Kafka
  • Elasticsearch
  • REST APIs
  • gRPC services
  • File systems
  • Disk space
  • Memory
  • Custom services

HTTP Response

Healthy

HTTP 200
{
    "status":"UP"
}

Unhealthy

HTTP 500
{
    "status":"DOWN"
}

Why health-service?

Many applications need a health endpoint for monitoring systems such as Kubernetes, Docker, cloud load balancers, and observability platforms.

health-service focuses on providing this functionality with minimal complexity.

Unlike framework-specific solutions, it has no dependency on Express, Fastify, NestJS, or Koa. The same health check implementation can be reused across different Node.js frameworks.


Design Principles

  • Framework independent
  • Minimal API surface
  • Simple extension model
  • Single responsibility
  • Type-safe
  • Zero runtime dependencies
  • Production friendly

Related Projects

This library is part of the core-ts ecosystem.

  • config-plus — Configuration management
  • validation-core — Data validation
  • security-express — Authorization middleware
  • authentication-express — Authentication middleware
  • express-jsonwebtoken — JWT verification
  • authen-service — Authentication service
  • password-service — Password management
  • signup-service — User registration
  • sql-core — Database abstraction and repository framework
  • mysql2-core — MySQL adapter for sql-core
  • io-one — Streaming import/export utilities

License

MIT