# npx @pulse-si/init

> One command links a NestJS or Next.js project to Pulse. It installs the package, writes the key, and wires up startup.

- Section: Packages
- Availability: NestJS and Next.js, Node 18.17 or later. Laravel, Symfony, Python and Go are installed by hand.
- URL: https://pulse-app.si/en/docs/packages/init

## Run the command

Run it at the project root, with the key the Pulse app shows you.

**zsh**

```text
$ npx @pulse-si/init pk_live_…
NestJS project detected (pnpm).

Choose what your app sends to Pulse. The heartbeat is always sent.
Found in package.json: Prisma, Redis (ioredis), BullMQ, scheduled jobs.
  Dependency health (database, Redis, queues)? [Y/n]
  Scheduled jobs? [Y/n]
  App logs (Pro and Team)? [Y/n]
  Versions (app, framework, deployment)? [Y/n] n
  Checks or jobs to skip (comma-separated names, * allowed, empty for none): File emails
  Minimum log level (DEBUG, INFO, WARN, ERROR) [DEBUG]: INFO

Secure mode (Pro and Team): everything is sent encrypted, Pulse can’t read any of it.
  Public key pulse_pub_… shown in the app (empty to skip):
✓ @pulse-si/nest installed
✓ Key added in .env
✓ Settings written: PULSE_SEND, PULSE_EXCLUDE, PULSE_LOG_LEVEL
✓ PulseModule wired in src/app.module.ts

.env stays on this computer. Where the app runs (Vercel, Docker, your server), add:
  PULSE_KEY=pk_live_…
  PULSE_SEND=checks,crons,logs
  PULSE_EXCLUDE=File emails
  PULSE_LOG_LEVEL=INFO

Restart your app: the first signal shows up in Pulse.
```

The questions cover, in order: dependency state, scheduled jobs, logs, versions, names to ignore, the minimum log level, and the secure mode public key. Return keeps the suggested answer. The environment file doesn’t ship with your code: copy the lines shown at the end to wherever the app runs in production. Then restart the app. The first report goes out 2 seconds after startup.

> **Secure mode: leave it empty**
>
> The app screen that creates the `pulse_pub_…` key is coming soon. Until then, press Return at that question. See [All variables](https://pulse-app.si/en/docs/packages/variables#secure-mode).

## What it touches

| File | Change |
| --- | --- |
| `package.json` | Adds `@pulse-si/nest` or `@pulse-si/next` with your package manager. The rest of the file keeps its formatting. |
| `.env` (NestJS), `.env.local` (Next.js) | Adds `PULSE_KEY` and any settings that differ from the defaults. An existing line is replaced, never duplicated. The file becomes readable only by you (`600`). |
| `.gitignore` | Adds the environment file, if it isn’t already ignored. |
| `src/app.module.ts` or `src/app/app.module.ts` | NestJS: adds `PulseModule.forRoot()` to `imports`, plus its import line. |
| `instrumentation.ts` or `.js` | Next.js: created if missing, in `src/` if the project has `src/app` or `src/pages`. |

The command never calls Pulse, so the key is written only to your project. The only network access is the install by your package manager. Running the command again with a new key is safe.

### How it recognizes the project

- The framework comes from `package.json`: `@nestjs/core` for NestJS, otherwise `next` for Next.js.
- The package manager comes from the lockfile: `pnpm-lock.yaml`, `yarn.lock`, `bun.lockb` or `bun.lock`, `package-lock.json`. With none of them, it’s npm.
- A `tsconfig.json` gives you `instrumentation.ts`, otherwise `instrumentation.js`.
- Run from the root of a monorepo, it lists the NestJS and Next.js projects found up to two levels down and gives the command with `--dir`.

## Run without questions

Use these options for a script or CI. `--yes` keeps the default settings, and any of the data options below also skips the questions. `--dir`, `--endpoint` and `--fingerprint` leave them on. Without an interactive terminal, no questions are asked.

**zsh**

```bash
npx @pulse-si/init pk_live_… --yes
npx @pulse-si/init pk_live_… --send checks,crons --exclude "File *" --log-level WARN
npx @pulse-si/init pk_live_… --dir apps/helio-api --no-install
```

| Option | Purpose | Written to the file |
| --- | --- | --- |
| `--dir <path>` | Project folder, if it isn’t the current folder | Nothing |
| `--no-install` | Doesn’t install the package | Nothing |
| `--yes` | No questions, default settings | Nothing |
| `--send <list>` | Data to send: `checks`, `crons`, `logs`, `versions`, or `none` | `PULSE_SEND` |
| `--include <list>` | Only these checks and jobs, `*` allowed | `PULSE_INCLUDE` |
| `--exclude <list>` | Checks and jobs to ignore, `*` allowed | `PULSE_EXCLUDE` |
| `--log-level <level>` | `DEBUG`, `INFO`, `WARN`, `ERROR` or `FATAL` | `PULSE_LOG_LEVEL` |
| `--public-key <key>` | Secure mode public key | `PULSE_PUBLIC_KEY` |
| `--clear <list>` | In secure mode, what stays in the clear: `status`, `checks`, `crons`, `versions` or `none` | `PULSE_CLEAR` |
| `--endpoint <address>` | Your [Pulse Relay](https://pulse-app.si/en/docs/team/relay), as `https://` | `PULSE_ENDPOINT` |
| `--fingerprint <value>` | Certificate fingerprint of a relay without a domain | `PULSE_RELAY_FINGERPRINT` |

A wrong setting stops everything before anything is written. Default values aren’t written, which keeps the file readable.

## If it stops or asks you for something

| Message | What to do |
| --- | --- |
| `Clé invalide` | Invalid key: copy the whole key, `pk_live_…` or `pk_test_…`. |
| `Aucun projet NestJS ou Next.js ici` | No project found: run the command at the project root, or pass `--dir` (in a monorepo, the command suggests the folders it found). For another framework, install [by hand](https://pulse-app.si/en/docs/packages/overview#choose). |
| `Installation impossible` | Install failed: run the command it shows, then run `npx @pulse-si/init` again. Nothing was written. |
| `À faire à la main dans …` | NestJS module not found, or `instrumentation` already exists: the command prints the lines to add and leaves your file alone. |
| `Attention : sans @nestjs/config` | Load `.env` yourself, for example `node --env-file=.env`, so `PULSE_KEY` gets read. |
| `Next.js 14 : active experimental.instrumentationHook` | Set this option to `true` in `next.config`. |

- [NestJS](https://pulse-app.si/en/docs/packages/nest): What the module finds, and how to tune it.
- [Next.js](https://pulse-app.si/en/docs/packages/next): Passing your clients to `startPulse`.
- [All variables](https://pulse-app.si/en/docs/packages/variables): What the environment file can contain.
