A delightful health monitoring middleware for Express that rewards you with a cat image when all your endpoints are healthy. Because monitoring should be fun!
- Simple Configuration: Configure endpoints to monitor via JSON or JS files
- Express Integration: Drop-in middleware for Express applications
- Periodic Monitoring: Automatically checks endpoint health at configurable intervals
- Visual Feedback: Returns a cat image when all endpoints are healthy, error response when not
- Flexible: Support for custom headers, timeouts, and check intervals
npm install catornot- Create a configuration file
catOrNot.config.json:
{
"endpoints": [
{
"url": "http://localhost:3000/api/status",
"method": "GET"
},
{
"url": "http://localhost:3000/api/database",
"method": "GET"
}
],
"checkInterval": 30000,
"timeout": 5000,
"healthPath": "/health"
}- Add to your Express application:
const express = require('express');
const catOrNot = require('catornot');
const app = express();
// Add the catornot health check
app.use(catOrNot('./catOrNot.config.json'));
app.listen(3000, () => {
console.log('Server running on port 3000');
console.log('Health check available at http://localhost:3000/health');
});- Visit
http://localhost:3000/health:- If all endpoints are healthy: You get a cat image!
- If any endpoint is unhealthy: You get a 503 error with details
| Option | Type | Default | Description |
|---|---|---|---|
endpoints |
Array | Required | List of endpoints to monitor |
checkInterval |
Number | 30000 | Interval between health checks (ms) |
timeout |
Number | 5000 | Request timeout for each endpoint (ms) |
healthPath |
String | "/health" | Path where health check endpoint is exposed |
enableMonitoring |
Boolean | true | Enable periodic background monitoring |
catImagePath |
String | "./cat.jpeg" | Path to custom cat image |
Each endpoint in the endpoints array can have:
{
"url": "http://example.com/health",
"method": "GET",
"headers": {
"Authorization": "Bearer token"
}
}const express = require('express');
const catOrNot = require('catornot');
const app = express();
app.use(catOrNot('./catOrNot.config.json'));const express = require('express');
const catOrNot = require('catornot');
const app = express();
app.use(catOrNot({
endpoints: [
{ url: 'http://localhost:3001/status', method: 'GET' },
{ url: 'http://localhost:3002/health', method: 'GET' }
],
checkInterval: 60000,
timeout: 3000,
healthPath: '/status'
}));const catOrNot = require('catornot');
const healthRouter = catOrNot('./catOrNot.config.json');
// Access the health checker
const checker = healthRouter.healthChecker;
// Perform manual check
async function checkHealth() {
const isHealthy = await checker.checkAll();
const status = checker.getStatus();
console.log('All healthy:', isHealthy);
console.log('Status:', status);
}
// Stop automatic monitoring
healthRouter.healthChecker.stopMonitoring();
// Start automatic monitoring
healthRouter.healthChecker.startMonitoring();const { createHealthChecker } = require('catornot');
const checker = createHealthChecker({
endpoints: [
{ url: 'http://localhost:3000/api', method: 'GET' }
],
timeout: 5000
});
// Manual check
checker.checkAll().then(healthy => {
console.log('Healthy:', healthy);
console.log('Status:', checker.getStatus());
});When all endpoints are healthy, you receive the cat image:
- Status Code: 200
- Content-Type: image/jpeg
- Headers:
X-Health-Status: healthyX-Endpoints-Status: JSON with endpoint details
- Body: Cat image (JPEG)
When any endpoint is unhealthy:
{
"message": "Service unhealthy - no cat today",
"allHealthy": false,
"endpoints": {
"http://localhost:3000/api/status": {
"healthy": false,
"lastCheck": "2025-10-11T12:00:00.000Z",
"error": "Request timeout",
"statusCode": null
},
"http://localhost:3000/api/database": {
"healthy": true,
"lastCheck": "2025-10-11T12:00:00.000Z",
"error": null,
"statusCode": 200
}
}
}Want to use your own cat image? Specify the path in the config:
{
"catImagePath": "./my-custom-cat.jpeg",
"endpoints": [...]
}Main function to create health monitoring router.
- Parameters:
configPathOrObject: String path to config file or configuration object
- Returns: Express Router with health endpoint
Create standalone health checker without Express router.
- Parameters:
configPathOrObject: String path to config file or configuration object
- Returns: HealthChecker instance
checkAll(): Check all endpoints, returns PromiseareAllHealthy(): Returns boolean indicating if all endpoints are healthygetStatus(): Returns detailed status objectstartMonitoring(): Start periodic health checksstopMonitoring(): Stop periodic health checks
MIT
Issues and pull requests welcome! Let's make health monitoring more fun together.