A simple middleware that returns the availability of the API and related services.
Install with:
npm install --save @sparkit-gmbh/express-health-check
Use it in your express app:
const app = require('express')();
const statusMonitor = require('@sparkit-gmbh/express-health-check');
// Default
app.use(statusMonitor());
// With DB Monitor (Mongoose / Sequelize / IORedis)
// With Custom URL Path
app.use(status({ path: '/api/status', db: true }));
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
res.send('hello world');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
});
{ path: '/status'}
{ api: true }
{ system: true }
{ db: true }
If DB is set to true
, a DB instance should be provided
- Mongoose
{ mongoose: mongoose }
- Sequelize
{ sequelize: sequelize }
- IORedis
{ ioredis: ioredisInstance }
- Mongoose ORM (MongoDB)
- Sequelize ORM (MySQL, PostgreSQL, SQlite, ...)
- IORedis (Redis)
- MongoDB (coming soon)
You can return any JSON data with the extras property
{
extras: {
infoA: 1234
infoB: 1234
infoC: 'somethin'
}
}
Suggestions or improvements are most welcomed ! Open an issue if you want to help.
Piraveen Kamalathas https://github.com/piraveen