# Node

The framework-agnostic server SDK — errors, outbound services, and databases, detected below the framework.


`@everock/sdk/node` is the framework-agnostic server SDK. The [Next.js](/docs/sdks/nextjs) and [NestJS](/docs/sdks/nestjs) packages are thin wrappers over it — reach for it directly on Express, Fastify, or any Node service.

## Install & init

Call it once at startup, before your server starts handling requests.

```ts title="instrument.ts"
import { init } from '@everock/sdk/node';

init({
  publicKey: process.env.EVEROCK_PUBLIC_KEY!,
  endpoint: process.env.EVEROCK_ENDPOINT!,
  environment: 'production',
});
```

## What it captures automatically

- **Uncaught exceptions** and unhandled promise rejections, via process hooks.
- **Outbound services** — it wraps `fetch` and `http`/`https`, so supported outbound calls can contribute service observations and health evidence.
- **Databases** — patches `pg`, `mysql2`, and `ioredis` drivers (which covers Prisma, Drizzle, Knex, and TypeORM on top). MongoDB via `instrument.mongo(client)`.


  Detection happens below the framework, so it works on Express, Fastify, Koa, or a bare HTTP server without any adapter.


## Express error middleware

```ts title="app.ts"
import { errorHandler } from '@everock/sdk/node';

// after your routes
app.use(errorHandler());
```

## Report manually

```ts title="anywhere"
import { captureError, track } from '@everock/sdk/node';

try {
  await job();
} catch (error) {
  captureError(error);
}

// record a call to something we can't auto-detect (a queue, a gRPC target)
track('payments-queue', ok, { kind: 'other' });
```

## Keep it light

The SDK is built to stay out of the way: a bounded queue that never grows your memory, and `sampleRate` to thin non-error events under heavy traffic. This option does not sample errors; bounded queues, privacy filters, and collector limits can still discard them.

```ts title="init"
init({
  publicKey: process.env.EVEROCK_PUBLIC_KEY!,
  sampleRate: 0.25, // keep 25% of non-error events; this option does not sample errors
});
```
