Skip to content

Instantly share code, notes, and snippets.

@nairihar
Last active June 21, 2018 11:12
Show Gist options
  • Save nairihar/5a9f3cf2b1b3218e282aafc5c6c4d27d to your computer and use it in GitHub Desktop.
Save nairihar/5a9f3cf2b1b3218e282aafc5c6c4d27d to your computer and use it in GitHub Desktop.
NodeJS Health Check and Overload Protection, medium
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.end(`Hello PID: ${process.pid}`);
});
let status = 200;
setTimeout(() => {
status = 503;
console.log('Status changed to 503');
}, 20000);
app.get('/check', (req, res) => {
console.log(`Health Check Request ${status}`);
res.status(status).end();
});
app.listen(process.env.PORT);
console.log(`Api Server running on ${process.env.PORT} port, PID: ${process.pid}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment