New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-healthchecker

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-healthchecker

Expose an express service health status

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
decreased by-63.64%
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 21 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc