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

@haensl/koa-health

v1.0.1

Published

Application health/readiness management and Koa routes.

Downloads

1

Readme

@haensl/koa-health

Application health/readiness management and koa routes.

NPM

npm version CircleCI

This module offers application health and readiness state management as well as accompanying koa routes that you can plug into your own Koa Router.

Motivation

Adding health and readiness endpoints to your microservices is a good practice that brings several benefits to your application's overall stability and reliability.

  1. Health Monitoring

    Health endpoints allow you to continuously monitor the state of your microservices. By regularly checking these endpoints, you can detect issues such as resource exhaustion, database connectivity problems, or other dependencies' failures. This proactive monitoring helps identify and address potential problems before they escalate.

  2. Load Balancing and Service Discovery

    Health and readiness endpoints enable load balancers and service discovery systems to determine the availability and capacity of your microservices. This information helps distribute incoming requests across healthy instances, ensuring optimal utilization and efficient resource allocation.

  3. Graceful Deployments

    Readiness endpoints can help control the deployment process by indicating when a microservice is ready to accept traffic. During deployments and/or scaling events, the readiness information can serve to re-route, delay or halt traffic until the service has completed initialization or maintenance tasks. This avoids serving requests to partially functioning instances.

  4. System Resilience

    Health endpoints facilitate the detection of failing or unhealthy services. Service health information enables orchestration systems to take automatic remedial actions, such as restarting unhealthy instances, spinning up new replicas, or triggering alerts for manual intervention. This enhances the overall system resilience and fault-tolerance.

Installation

Via npm

$ npm install -S @haensl/koa-health

Via yarn

$ yarn add @haensl/koa-health

Usage

  1. Install @haensl/koa-health

  2. Use state to manage your application's readyness and health state:

    const Koa = require('koa');
    const { state } =  require('@haensl/koa-health');
    
    const app = new Koa();
    
    const server = await app.listen(port);
    log.info(`listening on ${port}.`);
    
    // Set your app's state to healthy.
    state.setHealthy(true);
    
    app.on('error', (error) => {
      log.error('Uncaught error', error);
    
      // Update the app's state when an error occurs.
      state.setHealthy(false);
    });
    
    await database.init();
    // Signal that the app is ready to handle requests.
    state.setReady(true);
  3. Use routes to publish your application's readyness and health state:

    const Router = require('@koa/router');
    const { health, ready } = require('@haensl/koa-health/routes');
    
    const router = new Router();
    
    // add health routes
    router.get('/health', health);
    router.get('/ready', ready);
    
    // add other routes...
    
    app.use(router.routes());

state

@haensl/koa-health/state

The state module offers readyness and health state management.

state.isHealthy: () => boolean

Returns whether or not the service is currently in healthy state.

state.setHealthy: (boolean) => void

Sets the healthy state.

state.isReady: () => boolean

Returns whether or not the service is currently in ready state.

state.setReady: (boolean) => void

Sets the ready state.

routes

@haensl/koa-health/routes

Routes terminate the request and are meant to be used with Koa routers.

routes.health

Returns application health.

Throws 503 Service Unavailable if the app's health state is unhealthy.

routes.ready

Returns application ready state.

Throws 503 Service Unavailable if the app's state is not ready, yet.

Changelog

License