# NestJS

Server error capture for your NestJS backend — observe and rethrow, so your own error handling runs untouched.


`@everock/nest` captures server errors from your NestJS backend. It observes and rethrows, so your own exception handling runs untouched.

## Quick start



### Install the package

This adapter is available from the source checkout. Build its archive with `node scripts/pack-public-packages.mjs dist/npm 0.1.0-beta.1` at the repository root, then install the archive in your app using its actual path.

```bash
npm install /path/to/everock/dist/npm/everock-nest-0.1.0-beta.1.tgz
```

### Import the instrument entry first

It must load before anything else so it can wrap the runtime. Put it at the very top of `main.ts`.

```ts title="main.ts"
import '@everock/nest/instrument';

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();
```

### Register the module

Adds a global interceptor that captures handler errors and rethrows them.

```ts title="app.module.ts"
import { Module } from '@nestjs/common';
import { EverockModule } from '@everock/nest';

@Module({
  imports: [EverockModule.forRoot()],
})
export class AppModule {}
```




  Set `EVEROCK_PUBLIC_KEY` in your environment. The instrument entry reads it and starts the SDK; `forRoot()` calling `init()` again is a no-op.


## What's captured

- Errors thrown by controllers and providers, via the global interceptor.
- Uncaught exceptions and unhandled rejections, via the runtime hooks.
- Outbound calls (other APIs, databases) are detected automatically — see [Node](/docs/sdks/node).

## Report a handled error

```ts title="any service"
import { captureError } from '@everock/nest';

try {
  await chargeCard();
} catch (error) {
  captureError(error);
  throw error;
}
```
