Skip to content

Instantly share code, notes, and snippets.

@lovellfelix
Forked from PatrickKalkman/healthcheck.js
Created July 17, 2020 16:03
Show Gist options
  • Save lovellfelix/33e3f05888b41363df4d8ae1c3690958 to your computer and use it in GitHub Desktop.
Save lovellfelix/33e3f05888b41363df4d8ae1c3690958 to your computer and use it in GitHub Desktop.
Healthcheck cmd
const http = require('http');
const config = require('./config');
const log = require('./log');
const constants = require('./constants');
const options = {
host: 'localhost',
port: config.httpPort,
timeout: 2000,
method: 'GET',
path: '/api/health/',
};
const request = http.request(options, (result) => {
log.info(`Performed health check, result ${result.statusCode}`);
if (result.statusCode === constants.HTTP_STATUS_OK) {
process.exit(0);
} else {
process.exit(1);
}
});
request.on('error', (err) => {
log.error(`An error occurred while performing health check, error: ${err}`);
process.exit(1);
});
request.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment