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 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-healthchecker

v1.0.0

Published

Expose an express service health status

Downloads

133

Readme

npm version Build Status Coverage Status Dependency Status devDependency Status

Express healthchecker

Expose an express service health status.

Use

Install with:

npm install --save express-healthchecker

Write some health checks:

/*
*   A healthCheck is an object with the following properties:
*   - `name` (stirng): the name of the health check
*   - `checkHealth` (function): a function that returns (a promise to) a
*     healtResult
*
*   A healthResult is an object with the following properties:
*   - `isHealthy` (boolean): indicates the health status
*   - `details` (any) (optional): contains details about a check
*/
module.exports = {
    name: "myHealthCheck",
    checkHealth: () => {
        return Promise.resolve({
            isHealthy: false,
            details: "Problems occurred"
        });
    }
};

Use them in your express app:

const express = require("express");
const {healthRoute} = require("express-healthchecker");

const myHealthCheck = require("src/healthChecks/myHealthCheck");

express()
    .get("/health", healthRoute({
        healthChecks: [myHealthCheck],
        accessToken: process.env.HEALTH_ROUTE_ACCESS_TOKEN
    }));

When accessing the /health resource all checks are run and the resource responds with:

  • 200 Ok if the service is healthy (all checks pass)
  • 503 Service Unavailable if the service is unhealthy (some checks fail)

The body of the response is a JSON object with property isHealthy indicating the health status.

If an access_token matching the accessToken passed as option to healthRoute is provided in the querystring of the request, additional details are returned in the response.

Example requests/responses:

GET /health

200 OK
{
    "isHealthy": true
}

---

GET /health

503 Service Unavailable
{
    "isHealthy": false
}

---

GET /health?access_token=valid_access_token

200 OK
{
    "isHealthy": true,
    "details": {
        "myHealthCheck": {
            "isHealthy": true
        }
    }
}

---

GET /health?access_token=valid_access_token

503 Service Unavailable
{
    "isHealthy": false,
    "details": {
        "myHealthCheck": {
            "isHealthy": false,
            "details": "Problems occurred"
        }
    }
}

Contributing

See CONTRIBUTING.