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

healthchecks-io-client

v1.0.4

Published

A library for interacting with the Healthchecks.io API

Downloads

237

Readme

Healthchecks.io API Client GitHub package.json version Build Status Coverage Status codecov

The healthchecks-io-client library contains two simple and convenient HTTP clients for making requests to the Healthchecks.io Ping API and the Healthchecks.io Management API.

Table of contents

Installation

Using NPM:

$ npm install healthchecks-io-client

Using Yarn:

$ yarn add healthchecks-io-client

Usage

Initializing a client

The library exports two classes for interacting with the Healthchecks.io APIs and a ping shorthand/wrapper function. The HealthChecksPingClient class interacts with the Healthchecks.io Ping API. The HealthChecksApiClient class interacts with the Healthchecks.io Management API.

For a HealthChecksPingClient instance, you'll need the uuid of a health check. For a HealthChecksApiClient instance, you'll need an API key provided by Healthchecks.io. You can provide the API key as an apiKey option or set the API key as an environment variable using HC_API_KEY. By default, the client will use the HC_API_KEY environment variable if the apiKey option is not provided.

Example import methods:

const {
  HealthChecksPingClient,
  HealthChecksApiClient
} = require('healthchecks-io-client');

// Creating a ping API client.
const pingClient = new HealthChecksPingClient({
  uuid: 'HEALTH-CHECKS-UUID'
});

// Creating a management API client.
const apiClient = new HealthChecksApiClient({
  apiKey: 'HEALTH-CHECKS-API-KEY'
});
import {
  HealthChecksPingClient,
  HealthChecksApiClient
} from 'healthchecks-io-client';

// Creating a ping API client.
const pingClient = new HealthChecksPingClient({
  uuid: 'HEALTH-CHECKS-UUID'
});

// Creating a management API client.
const apiClient = new HealthChecksApiClient({
  apiKey: 'HEALTH-CHECKS-API-KEY'
});

For a HealthChecksApiClient instance, it is required to set the API key parameter as either an environment variable or as an option when instantiating the client. An API key is necessary to execute HealthChecksApiClient calls. If an API key is not provided or cannot be determined, then an error is thrown.

Using environment variables in an application:

const { HealthChecksApiClient } = require('healthchecks-io-client');

// Set the API key as an environment variable.
process.env.HC_API_KEY = 'HEALTH-CHECKS-API-KEY';

const apiClient = new HealthChecksApiClient();

Setting environment variables before running an application:

Linux:

$ HC_API_KEY=HEALTH-CHECKS-API-KEY node app.js

Windows:

> cmd /C "set HC_API_KEY=HEALTH-CHECKS-API-KEY && node app.js"

Options

HealthChecksPingClient Options:

These are the available options for creating a HealthChecksPingClient instance.

| Name | Default | Description | | ------------------- | ---------------------------- | ------------------------------------------------------------ |
| uuid | undefined | UUID of an existing health check | | timeout | 5000 | Number of milliseconds before the request times out | | baseUrl | https://hc-ping.com | Base URL for the Healthchecks.io Ping API | | returnResponse | false | Return the response from the request |

HealthChecksApiClient Options:

These are the available options for creating a HealthChecksApiClient instance.

| Name | Default | Description | | ------------------- | ---------------------------- | ----------------------------------------------------------------- | | apiKey | undefined | Healthchecks.io API Key | | timeout | 5000 | Number of milliseconds before the request times out | | baseUrl | https://healthchecks.io | Base URL for the Healthchecks.io Management API | | fullResponse | false | Get the full response instead of just the body | | maxContentLength | 10000 | The max size of the HTTP response content in bytes | | maxBodyLength | 2000 | The max allowed size of the HTTP request body in bytes |

Examples

HealthChecksPingClient Examples:

Create an instance:

const { HealthChecksPingClient } = require('healthchecks-io-client');

// Creating a ping API client.
const pingClient = new HealthChecksPingClient({
  uuid: 'HEALTH-CHECKS-UUID'
});

Send a "success" ping:

async function performTask() {
  /*
   * Add task logic here.
   */

  // Signal a "success" after completion.
  await pingClient.success();
}

Send a "success" ping on task completion and send a "fail" ping on task failure:

async function performTask() {
  try {
    /*
     * Add task logic here.
     */

    // Signal a "success" after completion.
    await pingClient.success();
  } catch(err) {
    // Send a "fail" ping on failure.
    await pingClient.fail();
  }
}

Alternatively, instead of exporting the HealthChecksPingClient you can export just the ping functionality.

// Export the 'ping' function.
const { ping } = require('healthchecks-io-client');

Send a "success" ping:

async function performTask(uuid) {
  /*
   * Add task logic here.
   */

  // Signal a "success" after completion.
  await ping(uuid, 'success');
}

Send a "success" ping on task completion and send a "fail" ping on task failure:

async function performTask(uuid) {
  try {
    /*
     * Add task logic here.
     */

    // Signal a "success" after completion.
    await ping(uuid);
  } catch(err) {
    // Send a "fail" ping on failure.
    await ping(uuid, 'fail');
  }
}

HealthChecksApiClient Examples:

Create an instance:

const { HealthChecksApiClient } = require('healthchecks-io-client');

// Creating a management API client.
const apiClient = new HealthChecksApiClient({
  apiKey: 'HEALTH-CHECKS-API-KEY'
});

Get a list of health checks:

async function getHealthChecks() {
  try {
    return await apiClient.getChecks();
  } catch(err) {
    console.error(err);
  }
}

Get a certain health check:

async function getHealthCheck(uuid) {
  try {
    return await apiClient.getCheck(uuid);
  } catch(err) {
    console.error(err);
  }
}

Create a new health check:

async function createHealthCheck() {
  try {
    return await apiClient.createCheck({
      name: 'App Check',
      tags: 'prod app',
    });
  } catch(err) {
    console.error(err);
  }
}

Documentation

HealthChecksPingClient Documentation:

ping Wrapper Documentation:

  • ping(uuid, action, payload) - Send a "success" or "fail" ping on task completion or task failure (with optional payload) - Healthchecks.io Documentation

HealthChecksApiClient Documentation:

Change Log

The CHANGELOG contains descriptions of notable changes.

License

This software is licensed under the Apache 2 license.