# errorgap for Node.js

See [index.md](./index.md) for API details and the placeholder values (`ERRORGAP_API_KEY`, `ERRORGAP_ENDPOINT`, `ERRORGAP_PROJECT_SLUG`).

SDK source: `github.com/errorgaphq/errorgap-node` · current version: `0.1.2`.

## Install

```sh
npm install @errorgap/node
```

Requires Node 20+.

## Configure

Create `errorgap.ts` (or `errorgap.js`) and import it as early as possible in the app entry point:

```ts
import { Errorgap } from "@errorgap/node";

Errorgap.init({
  endpoint:    process.env.ERRORGAP_ENDPOINT!,
  projectSlug: process.env.ERRORGAP_PROJECT_SLUG!,
  apiKey:      process.env.ERRORGAP_API_KEY!,
});
```

Set `ERRORGAP_*` in the app's environment (e.g. `.env`). Do not hardcode the key.

The SDK hooks `uncaughtException` / `unhandledRejection` automatically. Framework adapters are available as subpath exports:

```ts
// Express
import { errorgapErrorHandler } from "@errorgap/node/express";
app.use(errorgapErrorHandler()); // last middleware

// Fastify
import { errorgapPlugin } from "@errorgap/node/fastify";
await app.register(errorgapPlugin);
```

## Trigger a test error

Create `scripts/test-errorgap.ts` (run with `tsx`/`ts-node`, or use plain JS):

```ts
import "./../errorgap";

throw new Error("Errorgap test error");
```

## Verify

Run the verification curl from [index.md](./index.md) and confirm HTTP 201 with a `group_id`. Then run the test script above and confirm the errorgap onboarding screen advances (it polls for the first event every 3 seconds).
