> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keyport.sbs/llms.txt
> Use this file to discover all available pages before exploring further.

# NestJS

> Validate licenses inside NestJS with the official module, guard, and decorator integration.

## Installation

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
npm install keyport-nestjs
```

## Setup and usage

<Steps>
  <Step title="Register the module">
    Import `KeyPortModule` and call `forRoot` inside the `imports` array of your root `AppModule`. Supply your API key directly or point to a config file:

    <CodeGroup>
      ```typescript API key in code theme={"theme":{"light":"github-light","dark":"github-dark"}}
      imports: [
        KeyPortModule.forRoot({
          apiKey: process.env.KEYPORT_API_KEY!,
        }),
      ]
      ```

      ```typescript Config file theme={"theme":{"light":"github-light","dark":"github-dark"}}
      imports: [
        KeyPortModule.forRoot({
          configPath: './keyport.json',
        }),
      ]
      ```
    </CodeGroup>
  </Step>

  <Step title="Protect a route">
    Add the `@RequireLicense()` decorator to any controller method to enforce license validation on that endpoint:

    ```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
    @RequireLicense()
    @Get('protected')
    getProtected(@License() license) {
      return license;
    }
    ```

    Use the `@License()` parameter decorator to access the validated license payload inside the handler.
  </Step>
</Steps>

<Note>
  `@RequireLicense()` acts as a guard. Requests without a valid license key are rejected before your handler runs.
</Note>

<Tip>
  Load your API key from an environment variable (`process.env.KEYPORT_API_KEY`) or the NestJS `ConfigModule` rather than embedding it in source code.
</Tip>
