Docs Ping PingArk from Node.js

Ping PingArk from Node.js

Node 18 and newer ship a global fetch, so a ping is one line with no dependency. For scheduled jobs and framework integrations, the official pingark package wraps this with duration and failure tracking.

Before you start

You need a check and its ping URL. Create one in the dashboard, then copy the ping URL from the check page. New to PingArk? Start with the getting started guide.

Ping on success

Call the ping URL after your job finishes its work. A plain ping means success and re-arms the check for its next run.

// Node 18+ has fetch built in.
await fetch("https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e");
Copy

Report failures, starts and duration

Add a suffix to the ping URL to say more than a plain success. Call these the same way you called the success URL above. The ping API has the full reference.

https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e        # success: the job finished, re-arms the timer
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/start  # the run started, lets PingArk measure duration
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/fail   # an explicit failure, alerts right away
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/log    # a timeline note, never alerts
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/$?     # a shell exit code: 0 is success, anything else fails
Copy

On Node 18 or newer, fetch is global. On older versions, use node-fetch or the built in https module.

To report a failure, fetch the /fail URL from your catch block. To measure duration, fetch /start at the top and the success URL at the end.

Want automatic start and failure pings, or a Next.js, Express or Nuxt integration? Use the JavaScript SDK guide.

Troubleshooting

  • Always await the fetch, or a short lived process may exit before the ping is sent.
  • A ping failure should never throw into your job. Wrap it so a monitoring call cannot crash the task it is watching.