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.
Setup
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-tokenPing 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
});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}`);Run once
VERIFAGENT_URL='…' node job.mjs — expect { ok: true } and Up in the dashboard.
{"ok":true}Available routes
The base URL is enough for a heartbeat. Variants enrich history if your platform has several branches.
GET https://YOUR_PING_URLPOST https://YOUR_PING_URL/successPOST https://YOUR_PING_URL/fail?msg=ErrorVerify
Successful run → Up. Throw before ping() → no signal; Verifagent opens an incident after period + grace.
200 {"ok":true}. The monitor moves from Pending to Up.