> Set up the Pylo Node SDK for server-side data access with an API token

# Node Quickstart

The Node SDK (`@pylo/node`) gives you type-safe server-side access to your Pylo data with API key
authentication. Use it for backends, scripts, and internal tools.

## Install

```bash
# pnpm
pnpm add @pylo/node
# npm
npm install @pylo/node
# yarn
yarn add @pylo/node
```

## Generate types

Create an API token in **Settings > API Tokens** in the admin panel (see
[API Tokens](/authentication/api-tokens)) and put it in `.env`.

```bash filename=".env"
PYLO_API_KEY=your-api-token-here
```

```typescript filename="pylo.config.ts"
import { defineConfig } from '@pylo/node/codegen';

export default defineConfig({
  apiKey: process.env.PYLO_API_KEY!,
  output: '.pylo', // optional, defaults to '.pylo'
});
```

`pylo generate` loads `.env` and `.env.local` before reading the config.

```bash
# pnpm
pnpm exec pylo generate
# npm
npx pylo generate
# yarn
yarn pylo generate
```

This creates a `.pylo/` directory with your generated types.

> **When to regenerate**
> Rerun `pylo generate` after changing entities or fields in Pylo.

## Create the client

```typescript filename="lib/pylo.ts"
import { createPyloNode } from '@pylo/node';
import type { PyloSchema } from '../.pylo';

export const pylo = createPyloNode<PyloSchema>({
  apiKey: process.env.PYLO_API_KEY!,
});
```

The client has the same query and mutation API as the Next.js server client. All examples in the
[Data](/data/overview) section apply.

Next: [Querying](/data/querying)
