Node.js guide

Add a Verifagent heartbeat to a Node.js script

Native fetch is enough. Ping at the end of a successful run so crashes and thrown errors never send a heartbeat.

Before you start

Create a monitor with your workflow’s real frequency, then copy its URL from the dashboard. Its token is secret: do not publish it.

Module to use : fetch (Node 18+). Place it after the last useful action on the success path.

Setup

1

Copy the monitor URL

Create a monitor for this job’s cadence. Store the URL in VERIFAGENT_URL (or pass it as an argument).

https://verifagent.com/api/ping/your-ping-token
2

Ping only after success

Requires Node 18+. Await the real work, then fetch. Non-OK HTTP responses throw so a broken ping is visible in logs.

// Node.js 18+ const PING_URL = process.env.VERIFAGENT_URL; if (!PING_URL) { throw new Error("Missing VERIFAGENT_URL"); } async function doWork() { // Replace with your job } async function ping() { const response = await fetch(PING_URL, { method: "GET" }); if (!response.ok) { throw new Error(`Ping failed: HTTP ${response.status}`); } const body = await response.json(); console.log(body); // { ok: true } } async function main() { await doWork(); await ping(); } main().catch((error) => { console.error(error); process.exitCode = 1; // No ping on failure });
3

Optional POST variant

GET is enough for a heartbeat. POST works the same if you prefer it.

const response = await fetch(PING_URL, { method: "POST" }); if (!response.ok) throw new Error(`Ping failed: HTTP ${response.status}`);
4

Run once

VERIFAGENT_URL='…' node job.mjs — expect { ok: true } and Up in the dashboard.

{"ok":true}
Keep ping() after await doWork(). Match period to the scheduler; grace above cold-start and network latency for serverless hosts.

Available routes

The base URL is enough for a heartbeat. Variants enrich history if your platform has several branches.

GET https://YOUR_PING_URL
POST https://YOUR_PING_URL/success
POST https://YOUR_PING_URL/fail?msg=Error

Verify

Successful run → Up. Throw before ping() → no signal; Verifagent opens an incident after period + grace.

Expected response: 200 {"ok":true}. The monitor moves from Pending to Up.