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

pac-health-check

v1.1.1

Published

Health Check

Readme

Check

pipeline status coverage report

Install

$ npm install pac-health-check

Usage

Health Check by Cron Job

var healthCheck = require('pac-health-check');

/* Sample configuration */
 const configuration = {
	cron: '* */5 * * * *',
	max_retry: 2,
	services: {
		api: [{
			name: 'localhost 304',
			url: 'http://localhost:' + port + '/304',
			method: 'GET',
			expectedStatusCode: "200|202|304"
		}, {
			name: 'localhost 200',
			url: 'http://localhost:' + port + '/200',
			method: 'GET',
			expectedStatusCode: 200
		}],
		mssql: [{
			user: "username",
			password: "password",
			server: "server",
			port: 123,
			database: "database",
			connectionTimeout: 2000
		}],
		cas: [{
			seeds: "seed ip",
			keyspace: "key space",
			username: "username",
			password: "password"
		}],
		zkp: [{
			connectionString: "<host>:<port>/<root>"
		}],
		kaf: [{
			connectionString: "<host>:<port>/<root>/<kafka root>"
		}]
	}
};

//Init job
var job = healthCheck.initJob(configuration)

// Wait 5000ms to let the job run
setTimeout(function () {
    var result = healthCheck.reportJob();
    console.log(JSON.stringify(result));
    //Stop the job
    job.stop();
}, 5000)

Healch Check on Demand

healthCheck.reportOnDemand(configuration)

It is recommended to set a ttl configuration.ttl (in seconds).
If ttl is set, healthCheck will leverage local cache.

var healthCheck = require('pac-health-check');

//Sample configuration
var configuration = {
    ttl: 600,
    services: {
        api: [{
            name: 'httpstat.us 202',
            url: 'http://httpstat.us/202',
            method: 'GET',
            expectedStatusCode: "200|204",
            noncritical: true
        }, {
            name: 'httpstat.us 200',
            url: 'https://httpstat.us/200',
            method: 'GET',
            expectedStatusCode: 200
        }
        ]
    }
};

healthCheck.reportOnDemand(configuration)
    .then(function (result) {
        console.log(JSON.stringify(result));
    })
    .catch(function (error) {
        console.log(error);
    });

Health Check Offline

var healthCheck = require('pac-health-check');
healthCheck.offline();

Once offline method is called:

  • Both cron job and on demand request will stop perform actual health check. And health check cannont be resumed.
  • Health check status is DOWN, previous report is still accessible. (on demand request caching subjects to ttl)

Specification

Common Configuration Object

| RCO | Multitude | Property | Type | Description | | :--- | :--- | :----------------------------------------------- | :-------------------- | :---------------------------------------------------------------------------- | |C | 0-1 | cron | String |For health check by cron job flavor. Cron expression to run health check job(will run on init). | |C | 0-1 | ttl | Number | For healch check on demand flavor. The time to live as number in seconds for local health check report cache. 0 = unlimited | |O | 0-1 | max_retry | Number | Max retry to determine the application status is DOWN (critical dependency is DOWN). Default is 3.| |R | 1 | services | Object |services config for running actaul health check.| |R | 1-N | →{service} | Array of Object | Health Check for Supported Services | |C | 0-1 | →→noncritical | Boolean | If this service is critical. Optional, default is undefined/false. |

Supported Services:

  • api: Api Service
  • mssql: Microsoft SQL Server Service
  • cas: Cassandra Service
  • zkp: Zookeeper Service
  • kaf: kafka Service

Common Application Report Object

| Property | Type | Description | | :-------------------------------------- | :------------------------ | :------------------------------------------------------------ | | status | String | Value is UP, DOWN, DEGRADED. Check Overall Status section for detail. | | max_retry | Number | From max_retry property in configuration, Default is 3. | | services | Object | Health check report in detail for each service in configuration. | | → {service}[index].status | String | Value is UP, DOWN. Check each service section of detail. | | → {service}[index].noncritical | Boolean | From configuration services.{service}[index].noncritical property|

Overall Status

  • status is UP, When services.{service}[index].status is UP in all services.

  • status is DOWN, When any non noncritical servise services.{service}[index].status is DOWN.

  • status is DEGRADED, only if any noncritical servise services.{service}[index].status is DOWN.

Service api

Configuration

| RCO | Multitude | Property | Type | Description | | :--- | :--- | :------| :------| :------------------------------ | |R | 1 | name | String | Name of the API | |R | 1 | url | String | Url for health check| |R | 1 | method | String | Http method, only support GET for now. | |O | 1 | services.api[index].expectedStatusCode | Number/String | Optional, accpet: Number(e.g.200); RegEx String(e.g."202|204"). Default value is "^[1-3][0-9]{2}$". |

Report

| Property | Type | Description | | :-------------------------------------- | :------------------------ | :------------------------------------------------------------ | | services.api[index].name | String | From configuration | | services.api[index].url | String | From configuration | | services.api[index]. method | String | From configuration | | services.api[index].status | String | Check Api Status | | services.api[index].expectedStatusCode | String | From configuration.| | services.api[index].currentStatusCode | Number | Actaul http status from response. |

Api Status

  • report.api[index].status is UP by default.

  • report.api[index].status is DOWN, when health check result actualStatusCode is not matching expectedStatusCode.

Service mssql

Configuration

| RCO | Multitude | Property | Type | Description | | :--- | :--- | :----------------------------------------------- | :-------------------- | :---------------------------------------------------------------------------- |R | 1 | server | String | Mssql Server hostname or IP | |R | 1 | port | Number | Mssql Server port| |R | 1 | database | String | Mssql database | |C | 1 | user | String | Mssql username | |C | 1 | password | String | Mssql password | |O | 1 | connectionTimeout | Number | Optional, in miliseconds, default is 15000|

Report

| Property | Type | Description | | :-------------------------------------- | :------------------------ | :------------------------------------------------------------ | | services.mssql[index].server | String | From configuration | | services.mssql[index].database | String | From configuration | | services.mssql[index].status | String | Value is UP by default, DOWN when cannot connect to MsSql. |

Service cas

Configuration

| RCO | Multitude | Property | Type | Description | | :--- | :--- | :----------------------------------------------- | :-------------------- | :---------------------------------------------------------------------------- |R | 1 | seeds | String | Cassandra seeds | |R | 1 | keyspace | Number | Cassandra keyspace | |C | 1 | username | String | username | |C | 1 | password | String | password |

Report

| Property | Type | Description | | :-------------------------------------- | :------------------------ | :------------------------------------------------------------ | | services.cas[index].seeds | String | From configuration | | services.cas[index].keyspace | String | From configuration | | services.cas[index].status | String | Value is UP by default, DOWN when cannot connect to Cassandra. |

Service zkp

Configuration

| RCO | Multitude | Property | Type | Description | | :--- | :--- | :----------------------------------------------- | :-------------------- | :---------------------------------------------------------------------------- |R | 1 | connectionString | String | Zookeeper connection string. E.g. <host>:<port>/<root> |

Report

| Property | Type | Description | | :-------------------------------------- | :------------------------ | :------------------------------------------------------------ | | services.zkp[index].connectionString | String | From configuration | | services.zkp[index].status | String | Value is UP by default, DOWN when cannot connect to Zookeeper. |

Service kaf

Configuration

| RCO | Multitude | Property | Type | Description | | :--- | :--- | :----------------------------------------------- | :-------------------- | :---------------------------------------------------------------------------- |R | 1 | connectionString | String | Kafka connection string. E.g. <host>:<port>/<root>/<kafka root> |

Report

| Property | Type | Description | | :-------------------------------------- | :------------------------ | :------------------------------------------------------------ | | services.kaf[index].connectionString | String | From configuration | | services.kaf[index].status | String | Value is UP by default, DOWN when cannot connect to Kafka. |

Sample Report

Heath Check

{
	"status": "UP",
	"max_retry": 3,
	"api": [{
		"name": "localhost 304",
		"url": "http://localhost:9999/304",
		"method": "GET",
		"expectedStatusCode": "200|202|304",
		"currentStatusCode": 304,
		"noncritical": true,
		"status": "UP"
	}, {
		"name": "localhost 200",
		"url": "http://localhost:9999/200",
		"method": "GET",
		"expectedStatusCode": 200,
		"currentStatusCode": 200,
		"status": "UP"
	}],
	"mssql": [{
		"server": "10.1.1.1",
		"database": "Access",
		"status": "UP"
	}],
	"cas": [{
		"seeds": "10.1.1.2",
		"keyspace": "dev_def",
		"status": "UP"
	}],
	"zkp": [{
		"connectionString": "10.1.1.3:2181/dev",
		"status": "UP"
	}],
	"kaf": [{
		"connectionString": "10.1.1.4:2181/dev/kafka",
		"status": "UP"
	}]
}

Heath Check Offline

{
    "status": "DOWN",
    "max_retry": 2,
    "api": [{
        "name": "localhost 202",
        "url": "http://localhost:9999/202",
        "method": "GET",
        "expectedStatusCode": 202,
        "currentStatusCode": 202,
        "status": "UP"
    }, {
        "name": "localhost 202 2",
        "url": "http://localhost:9999/202",
        "method": "GET",
        "expectedStatusCode": 202,
        "currentStatusCode": 202,
        "status": "UP"
    }],
    "mssql": [{
        "server": "10.231.22.213",
        "database": "Access",
        "status": "UP"
    }, {
        "server": "10.231.22.212",
        "database": "Access",
        "status": "UP"
    }],
    "cas": [{
        "seeds": "10.231.23.40",
        "keyspace": "dev_def",
        "status": "UP"
    }, {
        "seeds": "10.231.23.41",
        "keyspace": "dev_def",
        "status": "UP"
    }],
    "zkp": [{
        "connectionString": "dev-usw-r1-def-h1:2181/dev",
        "status": "UP"
    }, {
        "connectionString": "dev-usw-r2-def-h2:2181/dev",
        "status": "UP"
    }],
    "kaf": [{
        "connectionString": "dev-usw-r1-def-h1:2181/dev/kafka",
        "status": "UP"
    }, {
        "connectionString": "dev-usw-r2-def-h2:2181/dev/kafka",
        "status": "UP"
    }],
    "offline": true
}

Test

Test Coverage

|File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | |-----------------|----------|----------|----------|----------|-------------------| |All files | 100 | 97.41 | 100 | 100 | | | src | 100 | 95 | 100 | 100 | | | → consts.js | 100 | 100 | 100 | 100 | | | → healthcheck.js | 100 | 94.44 | 100 | 100 | 66,96,99 | | src/component | 100 | 100 | 100 | 100 | | | → api.js | 100 | 100 | 100 | 100 | | | → cas.js | 100 | 100 | 100 | 100 | | | → kaf.js | 100 | 100 | 100 | 100 | | | → mssql.js | 100 | 100 | 100 | 100 | | | → zkp.js | 100 | 100 | 100 | 100 | |