DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor a Node.js API with Multi-Region Health Checks

If you're building a Node.js API, you already know the basics: write endpoints, add error handling, deploy. But how do you know your API is actually up and responding correctly—across different regions of the world—without paying enterprise monitoring prices?

This tutorial walks through setting up robust multi-region health monitoring for a Node.js API using Vigilmon, with Slack alerts when things go wrong.

Step 1: Add a Health Check Endpoint

Before you can monitor your API, you need something to monitor. A proper /health endpoint returns structured status information that monitoring tools can parse.

// health.js - Express health check endpoint
const express = require('express');
const router = express.Router();

router.get('/health', async (req, res) => {
  const checks = {
    uptime: process.uptime(),
    timestamp: new Date().toISOString(),
    status: 'ok',
  };

  // Optional: check database connectivity
  try {
    await db.raw('SELECT 1');
    checks.database = 'ok';
  } catch (err) {
    checks.database = 'error';
    checks.status = 'degraded';
  }

  const statusCode = checks.status === 'ok' ? 200 : 503;
  res.status(statusCode).json(checks);
});

module.exports = router;
Enter fullscreen mode Exit fullscreen mode

Mount it in your main app:

const healthRouter = require('./health');
app.use('/api', healthRouter);
Enter fullscreen mode Exit fullscreen mode

Now GET /api/health returns:

{
  "uptime": 3842.5,
  "timestamp": "2024-01-15T10:30:00.000Z",
  "status": "ok",
  "database": "ok"
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Free Vigilmon Account

Head to vigilmon.online and sign up for free. No credit card required.

Vigilmon's free tier includes:

  • 1-minute check intervals
  • Multi-region concurrent checks (the key feature—more on this below)
  • Slack and email alerts
  • Response time history

Step 3: Add Your API as a Monitor

After logging in:

  1. Click New Monitor
  2. Set URL to https://your-api.com/api/health
  3. Set Method to GET
  4. Set Expected Status to 200
  5. Optionally add a Response Body Check: verify the response contains "status":"ok"

For more robust monitoring, you can also check a specific JSON field. If your database goes down, your health endpoint returns 503, and Vigilmon will catch it.

Step 4: Why Multi-Region Matters for APIs

Here's a scenario that happens more than you'd think: your API is perfectly healthy, but a regional network issue causes a single monitoring probe to time out. Single-location monitors fire a false alert. Your phone buzzes at 2am. Everything is actually fine.

Vigilmon solves this with consensus checking: it runs simultaneous checks from multiple regions on every cycle. An alert only fires when a majority of regions agree your API is unreachable.

For a Node.js API with global users, this matters because:

  • CDN edge issues can make your API appear down from one region
  • DNS propagation delays affect single-location monitors
  • Regional network congestion causes spurious timeouts

With consensus checking, these all get filtered out automatically—no configuration needed.

Step 5: Configure Slack Alerts

In your Vigilmon dashboard:

  1. Go to Alert ChannelsAdd Channel
  2. Select Slack
  3. Paste your Slack Incoming Webhook URL
  4. Choose which monitors trigger this channel

When your API goes down (confirmed across regions), you get a Slack message like:

🔴 ALERT: api.your-service.com is DOWN
Confirmed from: US-East, EU-West, Asia-Pacific
Response: Connection timeout
Detected: 2 minutes ago
Enter fullscreen mode Exit fullscreen mode

And when it recovers:

✅ RESOLVED: api.your-service.com is back UP
Total downtime: 4 minutes
Enter fullscreen mode Exit fullscreen mode

Step 6: Test Your Setup

Temporarily take your API offline (or return a 503 from /health) and verify:

  1. Vigilmon detects the failure within 1-2 minutes
  2. You receive a Slack alert
  3. When you restore service, you get a recovery notification

What You've Built

You now have:

  • A structured health endpoint that reflects real API status (including database connectivity)
  • Multi-region monitoring that eliminates false positive alerts
  • Slack notifications triggered only on genuine outages
  • 1-minute check intervals on the free tier

Going Further

Once you have basic monitoring working, consider:

  • Response time tracking: Vigilmon records latency per check so you can spot performance degradation before it becomes an outage
  • Status page: Generate a public status page to communicate incidents to your users
  • Webhook alerts: Trigger custom workflows when your API goes down—PagerDuty, incident.io, or your own handler

Start Monitoring Free

Setup takes under 5 minutes. Create your free Vigilmon account and add your Node.js API today.

Multi-region health checks shouldn't require an enterprise budget. With Vigilmon's free tier, they don't.

Top comments (0)