---
title: "Ping CronMissed from Node.js"
url: "https://cronmissed.com/snippets/nodejs.md"
canonical_url: "https://cronmissed.com/snippets/nodejs"
last_updated: "2026-10-22"
type: "how-to"
summary: "A Node.js helper using built-in fetch that reports start, success and failure to CronMissed with a timeout and the tail of the stack trace."
related: ["https://cronmissed.com/snippets.md", "https://cronmissed.com/guides/node-cron.md", "https://cronmissed.com/guides/vercel-cron.md", "https://cronmissed.com/guides/cloudflare-cron-triggers.md", "https://cronmissed.com/snippets/shell.md"]
---

# Ping CronMissed from Node.js

> **For AI agents:** the complete index of CronMissed pages is [llms.txt](https://cronmissed.com/llms.txt). Every page is also served as markdown at its URL plus .md.

A Node.js helper using built-in fetch that reports start, success and failure to CronMissed with a timeout and the tail of the stack trace.

Node 18 and later ship fetch and AbortSignal.timeout, so a ping needs no dependency. This wrapper reports the start, then success, or failure with the end of the stack trace, and it never lets a failed ping throw.

## What should a Node.js job send?

- A request to `/start` before the work, so CronMissed can time the run and notice a job that never finishes.
- A request to the plain URL when the work succeeded, or to `/fail` when it did not. `/<exit status>` works too: 0 is a success and any other number is a failure.
- The end of the output in the request body, up to 100,000 bytes, so the alert shows the error without a trip to the server.

## What is the wrapper?

```
const PING_URL = process.env.CRONMISSED_PING_URL;

async function ping(suffix = '', body) {
  try {
    await fetch(PING_URL + suffix, {
      method: body ? 'POST' : 'GET',
      body,
      signal: AbortSignal.timeout(10_000),
    });
  } catch {
    // a lost ping must never break the job
  }
}

export async function monitored(job) {
  await ping('/start');
  try {
    const result = await job();
    await ping();
    return result;
  } catch (error) {
    await ping('/fail', String(error?.stack ?? error).slice(-100_000));
    throw error;
  }
}

await monitored(async () => {
  // the work
});
```

Keep the ping URL in an environment variable or a secret store, never in a public repository: the URL is the check's only credential.

## Which schedulers does this fit?

The same wrapper works in a [Vercel route handler](https://cronmissed.com/guides/vercel-cron.md), a [Cloudflare scheduled handler](https://cronmissed.com/guides/cloudflare-cron-triggers.md), an [AWS Lambda](https://cronmissed.com/guides/aws-eventbridge.md), a [node-cron task](https://cronmissed.com/guides/node-cron.md) and a [Railway cron service](https://cronmissed.com/guides/railway-cron.md). Await the pings before the process exits; in serverless runtimes an unawaited request can be cut off when the function returns.

## Questions

### Do I need node-fetch or axios?

No, on current Node versions. fetch is built in, and a ping is one request.

### Why await the ping?

In a serverless function the runtime may freeze the process as soon as the handler returns, so a request that was not awaited can be lost. In a long-running server it does not matter.

## Related pages

- [node-cron](https://cronmissed.com/guides/node-cron.md)
- [Vercel Cron Jobs](https://cronmissed.com/guides/vercel-cron.md)
- [Cloudflare Cron Triggers](https://cronmissed.com/guides/cloudflare-cron-triggers.md)
- [Shell and curl](https://cronmissed.com/snippets/shell.md)

## Related

- [Ping snippets for 12 languages and tools](https://cronmissed.com/snippets.md)
- [Monitor node-cron scheduled tasks](https://cronmissed.com/guides/node-cron.md)
- [Vercel cron jobs: schedule and monitor runs](https://cronmissed.com/guides/vercel-cron.md)
- [Monitor Cloudflare Workers Cron Triggers](https://cronmissed.com/guides/cloudflare-cron-triggers.md)
- [Ping CronMissed from a shell script with curl](https://cronmissed.com/snippets/shell.md)
