0.3.6 • Published 7 years ago

services-healthcheck v0.3.6

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

services-healthcheck

Build Status
Simple module to check the health status of a service dependencies

Installing

To install it, just use npm:
npm i services-healthcheck

Usage

Parameters

  • services:
    An object mapping the service name to its URL or to it's URL getter (the service must have a /_ping route), or to a knex connection. Supported DB's: Postgres, MSSQL, MySQL, MariaDB, SQLite3, and Oracle.
const express = require('express');
const knex = require('knex');
const healthcheck = require('services-healthcheck').default;

const getRandomArbitrary = (min, max) => {
  return Math.random() * (max - min) + min;
};

const getServiceUrl = () => return `http://service-{getRandomArbitrary(5, 10)}`;

const knexInstance = knex({
  client: 'mysql',
  connection: {
    host: 'localhost',
    user: 'user',
    password: 'password',
    database: 'database',
    port: 3306,
  },
  debug: false,
});

const services = {
  'service-1': 'http://service-1',
  'service-2': 'http://service-2',
  'service-3': 'http://service-3',
  'service-4': 'http://service-4',
  'service-5': { url: 'http://service-custom-ping', route: '/health/_ping' },
  'service-x': getServiceUrl,
  'db-1':      { knex: knexInstance },
  'queue-1':   { queue: { host: 'localhost', port: '5672' } }
};

function application() {
  const app = express();
  app.use(healthcheck(services));
  return app;
};

async function start() {
  const app = await application();
  app.listen(3000, () => console.log('http://localhost:3000'));
}

start();

After that, it will add a /_health route, that returns the status of the services passed

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago