DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your Bun Application with Vigilmon

How to Monitor Your Bun Application with Vigilmon

Bun is a blazing-fast JavaScript runtime that's rapidly gaining adoption. This guide shows how to add uptime monitoring to your Bun application using Vigilmon.

Native Bun HTTP Server

const server = Bun.serve({
  port: 3000,
  fetch(req) {
    const url = new URL(req.url);

    if (url.pathname === '/health') {
      return new Response(
        JSON.stringify({
          status: 'ok',
          runtime: 'bun',
          version: Bun.version,
          timestamp: new Date().toISOString(),
        }),
        { headers: { 'Content-Type': 'application/json' }, status: 200 }
      );
    }

    return new Response('Not Found', { status: 404 });
  },
});

console.log(`Server running on port ${server.port}`);
Enter fullscreen mode Exit fullscreen mode

Elysia Framework (Most Popular Bun Framework)

import { Elysia } from 'elysia';

const app = new Elysia()
  .get('/health', () => ({
    status: 'ok',
    timestamp: new Date().toISOString(),
  }))
  .listen(3000);

console.log(`Running at ${app.server?.hostname}:${app.server?.port}`);
Enter fullscreen mode Exit fullscreen mode

Hono with Bun

import { Hono } from 'hono';

const app = new Hono();
app.get('/health', (c) => c.json({ status: 'ok' }));

export default { port: 3000, fetch: app.fetch };
Enter fullscreen mode Exit fullscreen mode

Database Health Check with Bun SQLite

import { Database } from 'bun:sqlite';

const db = new Database('app.db');

Bun.serve({
  port: 3000,
  fetch(req) {
    const url = new URL(req.url);

    if (url.pathname === '/health') {
      let dbStatus = 'ok';
      try {
        db.query('SELECT 1').get();
      } catch {
        dbStatus = 'error';
      }

      const ok = dbStatus === 'ok';
      return new Response(
        JSON.stringify({ status: ok ? 'ok' : 'degraded', db: dbStatus }),
        { status: ok ? 200 : 503, headers: { 'Content-Type': 'application/json' } }
      );
    }

    return new Response('Not Found', { status: 404 });
  },
});
Enter fullscreen mode Exit fullscreen mode

Add to Vigilmon

  1. Deploy your Bun app (Railway, Fly.io, Render, or a VPS)
  2. Go to vigilmon.online
  3. Click Add Monitor and enter your /health URL
  4. Set check interval: 1 minute
  5. Configure email, Slack, or webhook alerts

Why Monitor Bun Apps?

Bun starts fast and crashes fast. Without external monitoring you find out from users. Vigilmon pings your endpoint every minute from external servers and alerts you within 30 seconds of any failure.

Free tier includes 5 monitors with 1-minute intervals. Start at vigilmon.online.

Top comments (0)