# NestJS

> Add PulseModule to a NestJS app and it finds your database, Redis, BullMQ queues, and scheduled jobs automatically, then reports their state with no other code changes.

- Section: Packages
- Availability: From the Free plan, logs on Pro and Team. Node 18.17 or later, NestJS 10 to 12.
- URL: https://pulse-app.si/en/docs/packages/nest

## Install

At the project root, with the key the Pulse app shows you:

**zsh**

```bash
npx @pulse-si/init pk_live_…
```

The command installs `@pulse-si/nest`, writes the key to `.env` and adds the module to `src/app.module.ts`. See [what it touches](https://pulse-app.si/en/docs/packages/init#what-it-touches).

### By hand

**zsh**

```bash
npm install @pulse-si/nest
```

**src/app.module.ts**

```ts
import { PulseModule } from '@pulse-si/nest';

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

`PULSE_KEY` must be in `process.env`, through `@nestjs/config` or with `node --env-file=.env`. Restart the app. The first report goes out 2 seconds after startup.

## What the module finds automatically

At startup, then every 60 seconds, the module walks your app’s providers and their fields. It recognizes clients by their shape, without importing any of them.

| Dependency found | What Pulse does | Name shown |
| --- | --- | --- |
| Prisma (PostgreSQL, MySQL, SQL Server, SQLite) | `SELECT 1` | PostgreSQL, MySQL… |
| Prisma MongoDB, Mongoose | `ping` | MongoDB |
| TypeORM | `SELECT 1` | Depends on the engine |
| ioredis, node-redis | `PING` | Redis |
| BullMQ | Reads the number of waiting jobs | `File emails`, `File invoices`… |
| `@nestjs/schedule` | Schedule, last and next run | The cron’s name |

Each check has 5 seconds to respond and only reads. A report carries at most 20 checks and 50 jobs. Two clients of the same type show as `Redis` and `Redis (2)`. `PulseModule.forRoot({ autoDetect: false })` turns the search off.

## Scheduled jobs

NestJS knows when a job ran, not whether it succeeded. To report a failure, wrap the work with `PulseService`:

**invoices.service.ts**

```ts
constructor(private readonly pulse: PulseService) {}

@Cron('0 * * * *', { name: 'renew-subscriptions' })
renew() {
  return this.pulse.track('renew-subscriptions', () => this.subscriptions.renew());
}
```

The error is recorded in Pulse, then thrown again unchanged. A failing dependency, a job that crashed, or one more than 5 minutes past its scheduled run turns the app **Degraded**.

## Choose what is sent

The heartbeat is always sent. The rest is set by variables, or in `forRoot`, which takes priority over them:

**src/app.module.ts**

```ts
PulseModule.forRoot({
  send: ['checks', 'crons', 'logs'],
  exclude: ['File emails'],
  logLevel: 'WARN',
  probes: [httpProbe('Route /health', 'http://localhost:3000/health')],
});
```

> **60 characters for a probe name**
>
> The Node package doesn’t shorten the name of a probe you add. Past 60 characters, the API refuses the whole report and your log shows `Pulse unreachable: HTTP 400`.

## Logs

On Pro and Team, the package copies what your app writes to stdout and stderr (NestJS logger, pino, `console`), without changing anything you see in the terminal. Level and context are recognized, colors removed, and secrets masked before anything is sent.

**Log**

```text
[Nest] 4120  - 20/10/2026 12:12:56   ERROR [PaymentsService] Payment declined token=abc123
ERROR  PaymentsService  Payment declined token=***
```

Batches go out every 10 seconds, and every second when a device is viewing the app. The pace drops back about 30 seconds after you leave the screen. Logs are kept for 3 days on Pro, 7 days on Team. On Free, capture stops at the API’s first response.

## If nothing arrives

| Message | What to do |
| --- | --- |
| `PULSE_KEY is missing` | The variable isn’t loaded: check `@nestjs/config` or `--env-file`. |
| `PULSE_KEY is malformed` | Copy the whole key: `pk_live_…` or `pk_test_…`. |
| `Pulse key refused` | The key was replaced in the app: copy the new one, then restart. |
| `Pulse unreachable` | Network or firewall: the app keeps running and sending resumes automatically. |

- [All variables](https://pulse-app.si/en/docs/packages/variables): Every setting and its default.
- [Exactly what is sent](https://pulse-app.si/en/docs/packages/payload): The precise format of reports and logs.
- [Live logs](https://pulse-app.si/en/docs/apps/logs): Read and filter them in Pulse.
