Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created January 5, 2020 14:52
Show Gist options
  • Save PatrickKalkman/77dd7d84aba2eb9a1fe32efa62ed903a to your computer and use it in GitHub Desktop.
Save PatrickKalkman/77dd7d84aba2eb9a1fe32efa62ed903a 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