Health-check middleware for Express.
Returns either HTTP 200 or 500.
Features
- Fetches fields asynchronously (in parallel)
- Supports Promises
- Reports errors individually
- Custom and optional (non-failing) fields
var express = require('express'),
healthCheck = require('@entercom/health-check');
express.use(healthCheck());
exposes /health-check
with the following information:
{
}
Environment variables can be reported if they're useful.
var express = require('express'),
healthCheck = require('@entercom/health-check');
express.use(healthCheck({
env: [
'REDIS_HOST',
'ELASTIC_HOST'
]
}));
Can add custom fields to be reported. Thrown errors in custom fields will return a 500.
var express = require('express'),
healthCheck = require('@entercom/health-check');
express.use(healthCheck({
stats: {
searchExists: function () {
var searchService = require('./search');
return searchService && searchService.ping();
}
}
}));
Missing fields will return a 500.
var express = require('express'),
healthCheck = require('@entercom/health-check');
express.use(healthCheck({
required: [
'host',
'someName',
'REDIS_HOST'
],
stats: {
someName: someFunction
},
env: [
'REDIS_HOST'
]
}));
npm install --save @entercom/health-check