> ## 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.

# Node.js

> Use the official TypeScript and Node.js client to validate license keys and retrieve license details.

## Installation

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

## Setup and usage

<Steps>
  <Step title="Initialize the client">
    You can create a client by passing your API key directly, or by loading it from a config file.

    <CodeGroup>
      ```typescript API key in code theme={"theme":{"light":"github-light","dark":"github-dark"}}
      import { KeyPort } from 'keyport-node';

      const client = new KeyPort('kp_live_xxx');
      ```

      ```json keyport.json theme={"theme":{"light":"github-light","dark":"github-dark"}}
      {
        "api_key": "kp_live_xxx",
        "base_url": "https://api.keyport.sbs/api/v1",
        "timeout": 10000
      }
      ```
    </CodeGroup>

    When using a config file, load the client with `KeyPort.fromConfigFile`:

    ```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
    const client = await KeyPort.fromConfigFile('./keyport.json');
    ```
  </Step>

  <Step title="Validate a license key">
    Call `client.validate` with the license key you want to check:

    ```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
    const result = await client.validate({ license_key: 'ABCD-EFGH-IJKL-MNOP' });
    ```

    This sends a `POST /api/v1/validate` request and returns the validation result.
  </Step>

  <Step title="Retrieve license details">
    Call `client.getLicense` with the license key to fetch full license details:

    ```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
    const detail = await client.getLicense('ABCD-EFGH-IJKL-MNOP');
    ```

    This sends a `GET /api/v1/license/:key` request and returns the license detail object.
  </Step>
</Steps>

## Full examples

<CodeGroup>
  ```typescript API key in code theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { KeyPort } from 'keyport-node';

  const client = new KeyPort('kp_live_xxx');

  // Validate a license key
  const result = await client.validate({ license_key: 'ABCD-EFGH-IJKL-MNOP' });

  // Retrieve full license details
  const detail = await client.getLicense('ABCD-EFGH-IJKL-MNOP');
  ```

  ```typescript Config file theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { KeyPort } from 'keyport-node';

  const client = await KeyPort.fromConfigFile('./keyport.json');

  // Retrieve full license details
  const detail = await client.getLicense('ABCD-EFGH-IJKL-MNOP');
  ```
</CodeGroup>

<Tip>
  Store your API key in an environment variable or a `keyport.json` config file rather than hard-coding it in your source code.
</Tip>
