Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Created July 26, 2018 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpotts18/32bc95442fcb5f5003752f5146fa8704 to your computer and use it in GitHub Desktop.
Save jpotts18/32bc95442fcb5f5003752f5146fa8704 to your computer and use it in GitHub Desktop.
Node.js Healtcheck
const express = require('express');
const { sequelize } = require('../models');
const router = express.Router();
/**
* @swagger
* /api/health-check:
* get:
* summary: Diagnostic endpoint to server connectivity and smoke tests.
* tags:
* - Internal
* description: Show high level connectivity and health of server
* produces:
* - application/json
* responses:
* 200:
* description: OK
* 500:
* description: Server Error
*/
router.get('/health-check', (req, res, next) => {
const checkdb = sequelize.query('SELECT 1');
Promise.all([checkdb])
.then((result) => {
const status = {};
status.uptimeSeconds = Math.floor(process.uptime());
status.pid = process.pid;
status.platform = process.platform;
status.server = true;
if (result[0] !== null) {
status.db = true;
}
res.json(status);
})
.catch((e) => {
res.status(500);
next(e);
});
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment