2.0.0 • Published 5 years ago

@routes/health v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@routes/health npm.io

💪 health check route

Pass in a method checking application and/or machine health. If any error occur - the function should throw an error if anything is wrong.

If anything is wrong - the route will return error code (503) and calls the process to fire SIGTERM

Expose a health route with health check

const health = require('@routes/health');

function healthCheck() {
	if (!db.serverConfig.isConnected()) {
		throw new Error('Database not connected');
	}
}

app.get('/ping', ...);
app.get('/health', health(healthCheck));
...

Arguments

  • 1st argument is a function of health check. Should throw an error if anything is wrong. This function can be asynchronous.
  • 2nd argument is an options object:
NameTypeDefaultMeaning
timeoutNumber10,000The number of milliseconds to wait between test fail and process.exit action
loggerObjectconsoleA logger object containing error function that can accept an Error object

Example with all options

app.get(
	'/health',
	health(
		healthCheck,
		{
			timeout: 4000,
			logger: { error: (error) => send(error) },
		}
	)
);
2.0.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago