Start

Node.js

Send notifications from JavaScript and TypeScript on your server.

Install

Requires Node.js 22 or later.

npm install @appkeeprhq/node

Create an API token in Workspace settings → API tokens. Keep it in a server-side environment variable.

.env
APPKEEPR_API_TOKEN=YOUR_API_TOKEN

Send a message

Create a signups channel. The revos project is optional; create it first or omit project.

notify.mjs
import { Appkeepr } from "@appkeeprhq/node";

const token = process.env.APPKEEPR_API_TOKEN;
if (!token) throw new Error("Set APPKEEPR_API_TOKEN.");

const appkeepr = new Appkeepr({ token, project: "revos" });

const result = await appkeepr.messages.send(
  {
    channel: "signups",
    title: "New user registered",
    message: "jane@example.com created an account.",
    icon: "🎉",
  },
  { idempotencyKey: "signup-1042" },
);

console.log(result.notificationId);
node --env-file=.env notify.mjs

send returns { notificationId, outcome }. The outcome is created or duplicate.

The constructor's project is a default. Override it per message, or omit it from both places to send without a project.

All message fields →

Timeouts and errors

The SDK has no default timeout or automatic retries. Set a deadline and handle failures:

import { AppkeeprError } from "@appkeeprhq/node";

try {
  await appkeepr.messages.send(
    { channel: "signups", message: "A new account was created." },
    { idempotencyKey: "signup-1043", signal: AbortSignal.timeout(10_000) },
  );
} catch (error) {
  if (error instanceof AppkeeprError) {
    console.error(error.status, error.code, error.message);
  } else {
    console.error(error); // Network or timeout error.
  }
}

For a retry, reuse the same idempotency key and message. A timeout may happen after the server has accepted the message.

Next.js

Use the same SDK in the Node.js server runtime. Store the token in .env.local, without a NEXT_PUBLIC_ prefix.

lib/notifications.ts
import "server-only";

import { Appkeepr } from "@appkeeprhq/node";

export function getAppkeepr() {
  const token = process.env.APPKEEPR_API_TOKEN;
  if (!token) throw new Error("Set APPKEEPR_API_TOKEN.");

  return new Appkeepr({ token, project: "revos" });
}

Call getAppkeepr().messages.send(...) from a Route Handler or Server Action. Browser and Edge runtimes aren't supported.

On this page