npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@heimdall-monitor/sdk

v0.1.0

Published

Heimdall Monitor SDK — cron job heartbeat helper for Node.js

Readme

@heimdall-monitor/sdk

Node.js SDK for Heimdall Monitor — a typed, zero-dependency helper for sending cron job heartbeat pings.

The heartbeat endpoint is language-agnostic: any tool that can make an HTTP POST request works out of the box. The SDK is a convenience wrapper for Node.js projects.


Quick Start

npm install @heimdall-monitor/sdk

Requires Node.js 18 or later (uses native fetch).


Integration Examples

Both examples below call the same endpoint — pick whichever fits your stack.

Option 1 — Plain HTTP (works from any language or shell)

# Bash / curl — runs after your job succeeds
your-cron-job && curl -s -X POST https://heimdall.observer/api/v1/heartbeat/YOUR_TOKEN
# Python
import urllib.request
urllib.request.urlopen(
    urllib.request.Request(
        "https://heimdall.observer/api/v1/heartbeat/YOUR_TOKEN",
        method="POST"
    )
)
// Go
http.Post("https://heimdall.observer/api/v1/heartbeat/YOUR_TOKEN", "", nil)

Option 2 — Node.js SDK

import { ping, wrap, configure } from "@heimdall-monitor/sdk";

// ---- Simple: call ping() after your job completes ----
async function myBackupJob() {
  // ... your job logic ...
  await ping("YOUR_TOKEN");
}

// ---- Auto-wrap: ping is sent only on success ----
// If myBackupJob throws, no ping is sent → Heimdall alerts you
const protectedJob = wrap(myBackupJob, "YOUR_TOKEN");
await protectedJob();

// ---- CJS (require) also works ----
const { ping } = require("@heimdall-monitor/sdk");
await ping("YOUR_TOKEN");

Always await the ping (or the wrapped job) before your process exits. An unawaited ping() followed by process.exit() may drop the HTTP request before it is sent.


API Reference

ping(token, options?): Promise<void>

Sends POST https://heimdall.observer/api/v1/heartbeat with the token in the Authorization: Bearer <token> header. The token never appears in the URL by default — this keeps it out of access logs, proxies and APM traces.

| Parameter | Type | Default | Description | | ---------------------- | -------------------- | ---------- | ---------------------------------------------------------------------------------------------------------- | | token | string | — | Heartbeat token from the Heimdall dashboard (required — empty tokens throw immediately) | | options.throwOnError | boolean | false | Throw if the request fails or returns a non-2xx status | | options.verbose | boolean | false | Log a warning to stderr on error (no throw) | | options.timeoutMs | number | 10000 | Request timeout — protects your job from a hung server | | options.authMode | 'header' \| 'path' | 'header' | Where to send the token. 'path' uses the legacy capability URL (/heartbeat/:token) for older backends. |

Silent by default — errors never break your cron job.

// Default: silent
await ping("YOUR_TOKEN");

// Throw on failure (e.g. for CI jobs where you want hard failures)
await ping("YOUR_TOKEN", { throwOnError: true });

// Log warning without throwing
await ping("YOUR_TOKEN", { verbose: true });

// Custom timeout (fast-fail in short-lived serverless functions)
await ping("YOUR_TOKEN", { timeoutMs: 3000 });

wrap(fn, token, options?): T

Higher-order function that runs fn(...args) and calls ping(token) only if fn resolves successfully. If fn throws or rejects, no ping is sent — Heimdall detects the miss.

const protectedJob = wrap(async () => {
  // heavy job logic
}, "YOUR_TOKEN");

await protectedJob(); // ping sent on success, skipped on error

Note: the wrapped function does not preserve this. Use an arrow function or bind the method before wrapping: wrap(myJob.bind(ctx), 'YOUR_TOKEN').

configure(options): void

Override the default base URL globally. Call once at startup before any ping() calls.

import { configure, ping } from "@heimdall-monitor/sdk";

// For self-hosted Heimdall deployments
configure({ baseUrl: "https://my-self-hosted-heimdall.example.com" });

await ping("YOUR_TOKEN");
// → POST https://my-self-hosted-heimdall.example.com/api/v1/heartbeat
//   Authorization: Bearer YOUR_TOKEN

| Option | Type | Default | Description | | --------- | -------- | --------------------------- | ----------------------------------- | | baseUrl | string | https://heimdall.observer | Base URL for all heartbeat requests |


Design Principles

  • Zero runtime dependencies — uses Node.js native fetch (18+), no extra packages in your node_modules
  • Silent by default — ping failures never crash your cron job; opt into throwOnError or verbose as needed
  • No retry logic — intentional: a retry after failure could mask a real miss in a dead-man's switch scenario
  • Timeout protected — requests are aborted after timeoutMs (default 10s) so a hung server never stalls your job
  • Token safety — the token is sent in the Authorization header by default (never in the URL) and is never logged; it is redacted (<redacted>) from verbose warnings and from errors thrown with throwOnError: true
  • Fail fast on bad input — an empty token throws immediately (programming error, not a network failure)

Security

The heartbeat token is a credential

The token identifies one monitor and grants exactly one capability: sending a heartbeat to it. It cannot read data, change configuration or reach other monitors. Treat it as a secret anyway — anyone with the token can keep a monitor green.

The heartbeat endpoint accepts two forms:

| Form | Request | When to use | | ------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | | Header (recommended) | POST /api/v1/heartbeat with Authorization: Bearer <token> | SDKs, CI jobs, anything that can set headers. Keeps the token out of URLs and access logs. | | Path (capability URL) | POST /api/v1/heartbeat/<token> | cron, curl or any language with no header support. |

The capability-URL form is the established pattern for heartbeat pings (Healthchecks.io, Cronitor and UptimeRobot push monitors all use it) and is what makes the integration work from a bare curl one-liner. The SDK uses the header form by default.

If you must use the path form, remember that URLs show up in access logs, proxies and APM traces. To limit exposure:

  • Rotate or revoke the token from the dashboard if it leaks (deleting the monitor invalidates its token).
  • The SDK never logs the token — verbose mode and errors thrown with throwOnError: true are redacted (<redacted>) from the message, stack, cause and AggregateError.errors.
  • The backend never logs the token — not even a prefix — and rate-limits the endpoint (120 requests/minute per IP).
  • If your policy forbids secrets in URLs, use the header form (or route the heartbeat through your own proxy and inject the token there).

Reporting a vulnerability

Please report security issues privately to the maintainers instead of opening a public issue. Include reproduction steps and the affected version.

License

MIT