healthychecks

1.0.13 • Public • Published

This a module executing procedures, similar to Vertx healthchecks

Install

$ npm install healthychecks

Usage

healthychecks();

Example

var healthy = require('healthychecks');
var express = require('express');
var http = require('http');

var app = express();
var promise1 = () => Promise.resolve(3);
var promise2 = () => Promise.resolve("ciaone");

//You can pass an array of procedures if you wanted
var procedures = [{ root: "path1", procedureFunction: promise1 }, { root: "path2", procedureFunction: promise2 }]
var healthyChecks = healthy(procedures)
var procedureFunction = () => new Promise((resolve, reject) => {
    //Write your procedure code here. It can be anything
    //Resolve wih an optional status "UP": OK(myCustomObject) adds an OK status property to myCustomObject
    //You can also reject with an optional status "DOWN" with KO(myCustomObject). Adds "DOWN" status property
    resolve(healthyChecks.OK({ mycustomKey: "message or something else" }));
})
//Register your procedure. Callback is optional
healthyChecks.register("register path", procedureFunction, (error, procedureEntry) => {
    //procedureEntry holds the procedure registered at "register path" 
    if (procedureEntry) {
        console.log(procedureEntry)
    } else {
        console.log(error)
    }
});
//Register the handler like you would with an express handler
app.use("/anypath", healthyChecks.createHandler())

app.listen(80, () => {
    var options = {
        port: 80,
        host: "localhost",
        method: 'GET',
        path: '/anypath',
    }
    http.request(options, (res) => {
        let response = '';
        res.on('data', (chunk) => response += chunk);
        res.on('error', (error) => console.log(error));
        res.on('end', () => {
            //for the example purpose, unregister the procedure when done
            //the root parameter must be the same as the registration's
            //expect [3,"ciaone",{"mycustomKey":"message or something else","status":"UP"}]
            healthyChecks.unregister("register path",(err,procedureEntry)=>{
                //Callback for catching any errors or to hold onto the unregistered procedure. Optional
            });
        });
    }).on('error', (error) => console.log(error)).end();
});

Readme

Keywords

Package Sidebar

Install

npm i healthychecks

Weekly Downloads

4

Version

1.0.13

License

ISC

Unpacked Size

12.8 kB

Total Files

4

Last publish

Collaborators

  • oracolo