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

hapi-alive

v2.0.4

Published

Health route for your Hapi.js server

Downloads

4,855

Readme

hapi-alive

Build Status Code Climate Test Coverage

Health route for your hapi.js server

Requirements

  • Node 8+
  • Hapi 17+

Usage

Install from NPM

npm install --save hapi-alive

Options

The defaults are as described below. You can override any defaults by passing them in as options.

const defaults = {
    path: '/health',
    tags: ['health', 'monitor'],
    responses: {
        healthy: {
            message: 'I\'m healthy!!!'
        },
        unhealthy: {
            statusCode: 400
        }
    },
    healthCheck: async function (_server) {

        return await true;
    },
    auth: false
};

Example

var Hapi = require('hapi');

async function createServer() {
    const server = Hapi.Server();

    // Register alive plugin
    await server.register({
        plugin: require('hapi-alive'),
        options: {
            path: '/health', //Health route path
            tags: ['health', 'monitor'],
            healthCheck: async function(server) {
                //Here you should preform your health checks
                //If something went wrong , throw an error.
                if (somethingFailed) {
                    throw new Error('Server not healthy');
                }
                return await true;
            }
        }
    });

    await server.start();

    console.log('Server running at:', server.info.uri);
}

Calling the health route

The health route is exposed using GET method in a given path (/health by default).

When the server is healthy the response status code should be 200.

When the health check returns error the status code should be 400 and the payload should contain the error title.

Change Log

  • v2.0.0 (Nov. 30th, 2017) Upgrade to Hapi 17
    • Hapi.js 17 suite of tool upgraded to latest.
    • healthCheck API converted to async/await pattern. Callback is no longer accepted.
  • v1.2.0
  • v1.1.0
  • v1.0.0