Server Health
Allows to easily add a /health
endpoint to a Restify, Express, Hapi
or native node http server returning vital information about a service.
Example output
Usage
Adding the /health endpoint to a restify server
See example/server.js for a complete example. Also check the tests for how to use this with hapi and express.
const restify = ;const serverHealth = ; serverHealth;serverHealth;serverHealth;const server = restify;serverHealth;server;
Querying from the command line
After adding the server info health endpoint to a service you can do a quick check
on its status using curl
and jq
:
> curl -s http://localhost:8080/health | jq '.status'"ok"
Filtering the response directly
Instead of filtering the whole response on the client the library also supports filtering server side by specifying a "filter" query string parameter.
Multiple properties can be queried by separating them by comma: filter=status,env.nodeEnv
> curl -s http://localhost:8080/health?filter=status{"status":"ok"}
Standalone Node Http Health Check Server
For services that do not have an existing Restify, Express, or Hapi Server, you can create a native Node HTTP Server that only has one route, that also provides the same health checks as Restify, Express, and Hapi servers.
const serverHealth = ;serverHealth;const options = endpoint: '/health' // optional and will default to `/health`;const nodeServer = serverHealth;nodeServer;