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

@myko.pk/health

v1.1.3

Published

Health check module for MYKO NestJS services

Readme

📑 Table of Contents

📝 Description

@myko.pk/health is an observability toolkit for MYKO NestJS services. It provides:

  • Health checks — register one or more check functions and get a standardised /health endpoint
  • System metrics — automatic CPU, memory, process, and OS metrics at /metrics
  • Custom metrics — track your own application-specific values (connections, queue depth, pool sizes, etc.)

All responses use the standard @myko.pk/response ApiResponse envelope.

✨ Key Features

  • 🩺 Health Checks — Register sync or async check functions per dependency (database, redis, etc.)
  • 📊 System Metrics — Automatic CPU usage, load averages, memory (total/free/used/heap), process info, OS info
  • ⚙️ Custom Metrics — Define your own numeric metrics with a collect callback
  • 🏗️ Dynamic ModulesforRoot() and forRootAsync() for both HealthModule and MetricsModule
  • 📦 Standard Response — All endpoints return ApiResponse via @myko.pk/response
  • 📘 Fully Typed — Full TypeScript support with interfaces for all metric types
  • 🔋 Zero Extra Dependencies — Metrics use only Node.js built-in node:os and process

⚡ Quick Start

npm install @myko.pk/health

Health Checks

import { Module } from '@nestjs/common';
import { HealthModule } from '@myko.pk/health';

@Module({
  imports: [
    HealthModule.forRoot([
      { name: 'database', check: async () => { /* return true/false */ } },
      { name: 'redis',    check: () => redis.ping() },
    ]),
  ],
})
export class AppModule {}

Access GET /health:

{
  "success": true,
  "statusCode": 200,
  "message": "Service healthy",
  "data": {
    "name": "myko-app",
    "uptime": 3600,
    "checks": [
      { "name": "database", "status": "up" },
      { "name": "redis",    "status": "up" }
    ]
  },
  "timestamp": "2026-07-04T12:00:00.000Z"
}

System + Custom Metrics

import { Module } from '@nestjs/common';
import { MetricsModule } from '@myko.pk/health';

@Module({
  imports: [
    MetricsModule.forRoot({
      customMetrics: [
        {
          name: 'active_connections',
          help: 'Active WebSocket connections',
          collect: () => wsServer.clients.size,
        },
      ],
    }),
  ],
})
export class AppModule {}

Access GET /metrics:

{
  "success": true,
  "statusCode": 200,
  "message": "Metrics collected",
  "data": {
    "system": {
      "cpu": {
        "usage": 34.2,
        "loads": [1.5, 0.8, 0.6]
      },
      "memory": {
        "total": 16777216000,
        "free": 8388608000,
        "used": 8388608000,
        "heapUsed": 512000000,
        "heapTotal": 1024000000
      },
      "process": {
        "uptime": 3600,
        "pid": 12345,
        "nodeVersion": "v22.0.0"
      },
      "os": {
        "hostname": "my-server-1",
        "platform": "darwin",
        "uptime": 99999
      }
    },
    "custom": {
      "active_connections": 42
    }
  },
  "timestamp": "2026-07-04T12:00:00.000Z"
}

Modules

HealthModule

| Method | Description | |--------|-------------| | forRoot(checks) | Register health checks synchronously | | forRootAsync(options) | Register health checks with dependency injection |

HealthCheck:

interface HealthCheck {
  name: string;
  check: () => Promise<boolean> | boolean;
}

HealthModule.forRootAsync:

HealthModule.forRootAsync({
  imports: [RedisModule],
  inject: [RedisService],
  useFactory: (redis: RedisService) => [
    { name: 'redis', check: () => redis.ping() },
  ],
})

MetricsModule

| Method | Description | |--------|-------------| | forRoot(options) | Register metrics collection with optional custom metrics | | forRootAsync(options) | Register metrics collection with dependency injection |

MetricsModuleOptions:

interface MetricsModuleOptions {
  customMetrics?: CustomMetricDefinition[];
}

CustomMetricDefinition:

interface CustomMetricDefinition {
  name: string;
  help: string;
  collect: () => number | Promise<number>;
}

API Reference

Endpoints

| Method | Path | Description | Module | |--------|------|-------------|--------| | GET | /health | Run all health checks, return aggregate status | HealthModule | | GET | /metrics | Collect system + custom metrics | MetricsModule |

Types

| Type | Description | |------|-------------| | SystemMetrics | CPU, memory, process, OS metrics | | CpuMetrics | usage (%), loads [1m, 5m, 15m] | | MemoryMetrics | total, free, used, heapUsed, heapTotal | | ProcessMetrics | uptime, pid, nodeVersion | | OsMetrics | hostname, platform, uptime | | CustomMetricDefinition | User-defined metric with name, help, collect callback | | MetricsResponse | Combined system + custom metrics |

DI Tokens

| Token | Description | |-------|-------------| | HEALTH_CHECKS | Injection token for registered health checks | | CUSTOM_METRICS | Injection token for custom metric definitions |

🚀 Available Scripts

  • buildnpm run build
  • devnpm run dev
  • typechecknpm run typecheck

👥 Contributors

See the full list of contributors →

👥 Contributing

Contributions are welcome! Here's the standard flow:

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/mykopk/health.git
  3. Branch: git checkout -b feature/your-feature
  4. Commit: git commit -m 'feat: add some feature'
  5. Push: git push origin feature/your-feature
  6. Open a pull request

Please follow the existing code style and include tests for new behavior where applicable.

📜 License

This project is licensed under the MIT License.

MYKO Pakistan

Detail Information Website myko.pk Email [email protected] About Building digital infrastructure and super-app experiences for millions of users across Pakistan. Built with ❤️ in Pakistan 🇵🇰