# Environment Variables

Store API keys and secrets outside your app code.

## Using env vars

Access them via `process.env`:

```tsx
const apiKey = process.env.OPENAI_API_KEY
if (!apiKey) throw new Error('Missing OPENAI_API_KEY')
```

Env vars are injected when your app starts. Changing them restarts the app automatically.

## Managing env vars

### CLI

```bash
toes env my-app                    # list env vars
toes env my-app set KEY value      # set a var
toes env my-app set KEY=value      # also works
toes env my-app rm KEY             # remove a var
```

### Dashboard

The `.env` tool in the tab bar lets you view and edit vars for the selected app. Values are masked until you click Reveal.

## Format

Standard `.env` syntax:

```
OPENAI_API_KEY=sk-...
DATABASE_URL=postgres://localhost/mydb
DEBUG=true
```

Keys are uppercased automatically. Quotes around values are stripped.

## Built-in variables

These are set automatically by Toes — you don't need to configure them:

- `PORT` - assigned port (3001-3100)
- `APPS_DIR` - path to the `/apps` directory
- `DATA_DIR` - per-app data directory (`toes/<app-name>/`) for storing persistent data
- `TOES_URL` - base URL of the Toes server
- `TOES_DIR` - path to the toes config directory
