Last active
June 21, 2018 11:12
-
-
Save nairihar/5a9f3cf2b1b3218e282aafc5c6c4d27d to your computer and use it in GitHub Desktop.
NodeJS Health Check and Overload Protection, medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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