health-check
An health check module for express and loopback
Install
npm install --save healthcheck-fastit
Usage
In your app, add the following code:
config = healthcheck = require'healthcheck-fastit' configappuse healthcheck
curl http://localhost/api/health-check
API response
"uptime": 42 // in seconds "postgres": "status": "ok" // or ko "mongo": "status": "ok" // or ko "elasticsearch": "status": "ok" // or ko
Database health check
Postgres
Example with postgres-node:
express = require 'express'pg = require 'pg' db = name: 'dbname' host: 'localhost' port: '5432' username: 'user' password: 'pwd' connectionString = "postgres://:@:/" config = postgres: client: connectionString app = expresshealthcheck = require'../main/src/module' configappuse healthcheck app.server = applisten 3000
Mongo
Example with mongo-db:
express = require 'express'mongodb = require 'mongodb' db = name: 'dbname' host: 'localhost' port: '5432' username: 'user' password: 'pwd'connectionString = "mongodb://:@:/" MongoClient = mongodbMongoClientmongoClient = app = express mongomongoClientconnect url return if err? config = mongo: client: db healthcheck = require'../main/src/module' config appuse healthcheck app.server = applisten 3000
Elasticsearch
elasticsearch = require 'elasticsearch'express = require 'express' config = host: 'localhost' port: 9200 app = express config = elasticsearch = client: host: confighost + ':' + configport log: 'debug' healthcheck = require'../main/src/module' configappuse healthcheck app.server = applisten 3000
Custom healthchecks
You can add your own healthchecks like this:
express = require 'express' config = custom: : done null'hello is OK!' : done null status: 'ok' somethingElse: 123 : done 'Unexpected error' # this error will be logged logger: console # you can specify here a logger with an "error" method to log errors app = expresshealthcheck = require'../main/src/module' configappuse healthcheck app.server = applisten 3000
Then the response looks like this:
uptime: "2.31 s" hello: "hello is OK!" dataConsistency: status: 'ok' somethingElse: 123