How to Monitor Your Bun Application with Vigilmon
Bun is the fast all-in-one JavaScript runtime — built-in bundler, test runner, package manager, and server. If you're running production services with Bun, you need uptime monitoring. This guide shows you how to add health checks to any Bun application and monitor it with Vigilmon.
Why Monitor Bun Applications?
- Bun apps can crash silently without a process manager
- Runtime panics don't always show up in logs immediately
- Memory leaks in long-running Bun servers need early detection
- Users hitting a dead endpoint is worse than getting an alert
Adding a Health Check Endpoint to Your Bun Server
Basic Bun.serve Health Check
// server.ts
const server = Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url);
// Health check endpoint
if (url.pathname === '/health') {
return new Response(JSON.stringify({
status: 'ok',
uptime: process.uptime(),
timestamp: new Date().toISOString(),
runtime: 'bun',
version: Bun.version,
}), {
headers: { 'Content-Type': 'application/json' },
});
}
// Your app routes here
return new Response('Hello from Bun!');
},
});
console.log(`Listening on http://localhost:${server.port}`);
With Database Check
import { Database } from 'bun:sqlite';
const db = new Database('app.db');
const server = Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url);
if (url.pathname === '/health') {
try {
// Test database connectivity
db.query('SELECT 1').get();
return new Response(JSON.stringify({
status: 'ok',
database: 'connected',
uptime: process.uptime(),
}), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
} catch (error) {
return new Response(JSON.stringify({
status: 'error',
database: 'disconnected',
error: error.message,
}), {
status: 503,
headers: { 'Content-Type': 'application/json' },
});
}
}
return new Response('Hello Bun!');
},
});
With Elysia Framework
import { Elysia } from 'elysia';
const app = new Elysia()
.get('/health', () => ({
status: 'ok',
runtime: 'bun',
version: Bun.version,
uptime: process.uptime(),
timestamp: new Date().toISOString(),
}))
.get('/', () => 'Hello Elysia!')
.listen(3000);
console.log(`Elysia running at http://localhost:${app.server?.port}`);
With Hono on Bun
import { Hono } from 'hono';
const app = new Hono();
app.get('/health', (c) => {
return c.json({
status: 'ok',
runtime: 'bun',
uptime: process.uptime(),
timestamp: new Date().toISOString(),
});
});
app.get('/', (c) => c.text('Hello Hono on Bun!'));
export default {
port: 3000,
fetch: app.fetch,
};
Heartbeat Monitoring for Bun Background Workers
If you have background workers in Bun (using Bun.CronJob or manual intervals), send heartbeats to Vigilmon:
// worker.ts
const HEARTBEAT_URL = 'https://vigilmon.online/api/heartbeat/YOUR_MONITOR_ID';
async function processJobs() {
// Your job processing logic
await processQueue();
// Send heartbeat to Vigilmon
await fetch(HEARTBEAT_URL, { method: 'POST' }).catch(console.error);
}
// Run every minute
setInterval(processJobs, 60_000);
console.log('Worker started');
Setting Up Vigilmon Monitoring
- Sign up at vigilmon.online
-
Add a new monitor → paste your health endpoint URL (e.g.,
https://api.yourdomain.com/health) - Configure alerts: email, Slack, or webhook
- Set check interval: 1 min or 5 min
- Add SSL monitoring for your domain
Vigilmon checks from multiple regions, so you'll know if your Bun app is down before your users do.
Keeping Bun Running in Production
Bun needs a process manager to restart on crashes:
# Using PM2
npm install -g pm2
pm2 start "bun run server.ts" --name my-bun-app
pm2 save
pm2 startup
# Using systemd
sudo nano /etc/systemd/system/bun-app.service
[Unit]
Description=Bun Application
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/app
ExecStart=/usr/local/bin/bun run server.ts
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
sudo systemctl enable bun-app
sudo systemctl start bun-app
Complete Monitoring Checklist for Bun Apps
- [ ]
/healthendpoint returning 200 with JSON status - [ ] Database connectivity check in health endpoint
- [ ] External dependency checks (Redis, external APIs)
- [ ] Uptime monitor on Vigilmon (1-min interval)
- [ ] SSL certificate monitor for your domain
- [ ] Heartbeat monitor for cron jobs / background workers
- [ ] Process manager (PM2 or systemd) for auto-restart
- [ ] Alert channels configured (email + Slack)
Summary
Monitoring a Bun application is straightforward:
- Add
/healthendpoint (returns 200 when healthy) - Connect to Vigilmon (paste the URL, done)
- Configure alerts
- Run Bun under a process manager
Vigilmon handles the rest — multi-region checks every minute, instant alerts if your Bun app goes down, SSL expiry warnings.
Top comments (0)