Express healthchecker
Expose an express service health status.
Use
Install with:
npm install --save express-healthchecker
Write some health checks:
/** A healthCheck is an object with the following properties:* - `name` (stirng): the name of the health check* - `checkHealth` (function): a function that returns (a promise to) a* healtResult** A healthResult is an object with the following properties:* - `isHealthy` (boolean): indicates the health status* - `details` (any) (optional): contains details about a check*/moduleexports = name: "myHealthCheck" { return Promise; };
Use them in your express app:
const express = ;const healthRoute = ; const myHealthCheck = ; ;
When accessing the /health
resource all checks are run and the resource
responds with:
200 Ok
if the service is healthy (all checks pass)503 Service Unavailable
if the service is unhealthy (some checks fail)
The body of the response is a JSON object with property isHealthy
indicating
the health status.
If an access_token
matching the accessToken
passed as option to
healthRoute
is provided in the querystring of the request, additional details
are returned in the response.
Example requests/responses:
GET /health 200 OK --- GET /health 503 Service Unavailable --- GET /health?access_token=valid_access_token 200 OK --- GET /health?access_token=valid_access_token 503 Service Unavailable
Contributing
See CONTRIBUTING.