How to Monitor Your Bun Application with Vigilmon
Bun is a fast all-in-one JavaScript runtime — 3–4x faster than Node.js for many workloads, with built-in bundler, transpiler, and test runner. As Bun gains production adoption, monitoring your Bun-powered API or server becomes essential. This guide shows how to set up uptime and endpoint monitoring for Bun apps with Vigilmon.
Why Monitor Your Bun App?
Bun apps share the same failure modes as any web server:
- Crashes due to unhandled errors
- Memory leaks causing OOM kills
- Deployment issues that break the endpoint
- SSL certificate expiry
- Slow response times
Vigilmon monitors the external behavior of your Bun app — giving you user-perspective visibility.
Step 1: Create a Health Endpoint
Bun has a native HTTP server — no framework needed for a simple health check:
// server.ts
Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url)
if (url.pathname === '/health') {
return Response.json({
status: 'ok',
runtime: 'bun',
version: Bun.version,
timestamp: new Date().toISOString()
})
}
if (url.pathname === '/') {
return new Response('Hello from Bun!')
}
return new Response('Not Found', { status: 404 })
}
})
console.log('Server running on http://localhost:3000')
Run with:
bun run server.ts
Step 2: Health Check with Database Connectivity
If your Bun app uses a database, include it in the health check:
import { Database } from 'bun:sqlite'
const db = new Database('app.sqlite')
Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url)
if (url.pathname === '/health') {
const checks: Record<string, string> = {}
let status = 'ok'
// Check SQLite connectivity
try {
db.query('SELECT 1').run()
checks.database = 'ok'
} catch (err) {
checks.database = 'error'
status = 'degraded'
}
return Response.json(
{ status, checks, timestamp: new Date().toISOString() },
{ status: status === 'ok' ? 200 : 503 }
)
}
return new Response('Not Found', { status: 404 })
}
})
Step 3: Using Elysia (Bun's Hono-like Framework)
Elysia is a Bun-first web framework with great TypeScript support:
import { Elysia } from 'elysia'
const app = new Elysia()
.get('/health', () => ({
status: 'ok',
runtime: 'bun',
version: Bun.version,
timestamp: new Date().toISOString()
}))
.get('/', () => 'Hello from Elysia on Bun!')
.listen(3000)
console.log(`Server running at http://${app.server?.hostname}:${app.server?.port}`)
Step 4: Dockerize Your Bun App for Production
FROM oven/bun:1.1 AS base
WORKDIR /app
FROM base AS deps
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile
FROM base AS release
COPY --from=deps /app/node_modules ./node_modules
COPY . .
EXPOSE 3000
ENTRYPOINT ["bun", "run", "server.ts"]
Step 5: Set Up Vigilmon Monitoring
- Sign up at vigilmon.online
- Click New Monitor → HTTP(S)
- Configure:
-
URL:
https://your-bun-app.com/health(or your server's IP/domain) - Interval: 1 minute
- Expected status: 200
- Timeout: 5 seconds
-
URL:
- Add alert channels: Slack, email, or webhook
Step 6: Process Manager for Production
For VM-deployed Bun apps, use PM2 or systemd to auto-restart on crash:
# ecosystem.config.js for PM2
module.exports = {
apps: [{
name: 'bun-api',
script: 'bun',
args: 'run server.ts',
watch: false,
autorestart: true,
max_restarts: 10,
env: {
NODE_ENV: 'production',
PORT: 3000
}
}]
}
pm2 start ecosystem.config.js
pm2 save
pm2 startup
Vigilmon will detect if PM2 restarts fail (app still down after restart) and alert you.
Step 7: Alert on Bun-Specific Issues
Common Bun production issues Vigilmon catches:
| Issue | Symptom | Vigilmon Alert |
|---|---|---|
| Unhandled promise rejection crashes process | 503 / connection refused | Downtime alert |
| Memory leak OOM kill | Sudden 503 burst | Downtime alert |
| Port bind failure on restart | Connection refused | Downtime alert |
| Bad deployment | 500 on all routes | Status code alert |
Summary
Bun's speed advantage is real — but speed means nothing if your service is down and nobody knows. Set up Vigilmon to monitor your Bun app in 5 minutes and get instant alerts when something goes wrong.
Free tier includes: 5 monitors, SSL monitoring, status pages, Slack/email alerts.
Top comments (0)