Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created January 5, 2020 14:52

Revisions

  1. PatrickKalkman created this gist Jan 5, 2020.
    28 changes: 28 additions & 0 deletions healthcheck.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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();