Cronping

Node.js

Ping Cronping from Node.js scripts and applications.

Node.js 18+ includes a built-in fetch API — no extra packages needed.

Using fetch (Node.js 18+)

const PING_URL = "https://ping.cronping.com/<token>";

async function pingCronPing() {
  try {
    await fetch(PING_URL, { signal: AbortSignal.timeout(10_000) });
  } catch (err) {
    console.error("Cronping ping failed:", err.message);
    // Don't throw — the job succeeded, only the notification failed
  }
}

async function main() {
  // ... your job logic ...

  await pingCronPing();
}

main().catch((err) => {
  console.error("Job failed:", err);
  process.exit(1);
});

Using https module (all Node.js versions)

const https = require("https");

function pingCronPing(token) {
  return new Promise((resolve) => {
    const req = https.get(
      `https://ping.cronping.com/${token}`,
      { timeout: 10_000 },
      (res) => {
        res.resume(); // drain the response
        resolve();
      },
    );
    req.on("error", (err) => {
      console.error("Cronping ping failed:", err.message);
      resolve(); // don't reject — job succeeded
    });
    req.on("timeout", () => {
      req.destroy();
      console.error("Cronping ping timed out");
      resolve();
    });
  });
}

async function main() {
  // ... your job logic ...
  await pingCronPing("<token>");
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

TypeScript

const PING_URL = "https://ping.cronping.com/<token>" as const;

async function pingCronPing(): Promise<void> {
  try {
    await fetch(PING_URL, { signal: AbortSignal.timeout(10_000) });
  } catch (err) {
    console.error(
      "Cronping ping failed:",
      err instanceof Error ? err.message : err,
    );
  }
}

async function runJob(): Promise<void> {
  // ... your job logic ...
}

runJob()
  .then(pingCronPing)
  .catch((err: unknown) => {
    console.error("Job failed:", err);
    process.exit(1);
  });

With node-cron

const cron = require("node-cron");

async function myJob() {
  // ... run the job ...

  // Ping on success
  try {
    await fetch("https://ping.cronping.com/<token>", {
      signal: AbortSignal.timeout(10_000),
    });
  } catch (err) {
    console.error("Cronping ping failed:", err.message);
  }
}

// Run every day at 3 AM
cron.schedule("0 3 * * *", myJob);

Start, fail, and exit code signals

const PING_URL = "https://ping.cronping.com/<token>";

async function ping(suffix = "") {
  try {
    const url = suffix ? `${PING_URL}/${suffix}` : PING_URL;
    await fetch(url, { signal: AbortSignal.timeout(10_000) });
  } catch {
    // Don't fail the job if the ping fails
  }
}

async function main() {
  await ping("start");
  try {
    await runBackup();
    await ping(); // success
  } catch (err) {
    await ping("fail"); // immediate Down alert
    throw err;
  }
}

main().catch((err) => {
  console.error("Job failed:", err);
  process.exit(1);
});

With axios

const axios = require("axios");

async function pingCronPing() {
  try {
    await axios.get("https://ping.cronping.com/<token>", {
      timeout: 10_000,
    });
  } catch (err) {
    console.error("Cronping ping failed:", err.message);
  }
}

On this page