← All postsSeptember 10, 2024 · 5 min read
How I built a lightweight uptime monitoring system to keep my hobby projects alive on free-tier hosting.
Node.jsDevOpsMonitoringUptimeFree Tier
Free-tier hosting platforms often spin down inactive applications. Here's how I built a system to keep them alive.
The Problem
Services like Render, Railway, and Heroku spin down free apps after 15-30 minutes of inactivity. This results in:
- Slow cold starts (30+ seconds)
- Poor user experience
- Missed webhook deliveries
The Solution
A lightweight Node.js service that:
- Pings your endpoints at regular intervals
- Logs response times and status codes
- Sends alerts on failures
- Provides a dashboard for monitoring
Implementation
const axios = require('axios');
const cron = require('node-cron');
const endpoints = [
'https://app1.example.com/health',
'https://app2.example.com/api/ping',
];
cron.schedule('*/5 * * * *', async () => {
for (const url of endpoints) {
const start = Date.now();
try {
const res = await axios.get(url, { timeout: 10000 });
console.log(`${url}: ${res.status} in ${Date.now() - start}ms`);
} catch (error) {
console.error(`${url}: FAILED - ${error.message}`);
// Send alert
}
}
});
Hosting the Monitor
The irony is you need a host that doesn't sleep. Options:
- GitHub Actions (cron workflow)
- Cloudflare Workers (free tier)
- Always-on VPS ($5/month)
Results
My free-tier apps now stay warm with consistent sub-second response times.