# Environment (/docs/starter/environment)

## Install the toolchain [#install-the-toolchain]

Install Node.js 22.12 or newer, then enable Corepack and install pnpm dependencies from the repository root:

```sh
corepack enable
pnpm install
```

The root `package.json` pins pnpm 10.9.0 through its `packageManager` field. Use a compatible pnpm 10 release if Corepack is not available.

If pnpm reports that it ignored a package build script needed by your environment, review the package name and approve only the required dependency with `pnpm approve-builds`.

With the FastAPI API, also [install uv](https://docs.astral.sh/uv/getting-started/installation/). The API needs Python 3.12 (`apps/api/.python-version`), which uv downloads when it isn't installed. The CLI runs `uv sync` in `apps/api` after `pnpm install`; in a fresh clone, the API's scripts run through `uv run`, which installs its dependencies on first use. Each module option has its own dependency group in `apps/api/pyproject.toml`: every project keeps the same `uv.lock`, development installs every group, and the production image only those of your modules.

## Create the environment file [#create-the-environment-file]

Projects generated by the CLI already have `apps/web/.env.local`. Otherwise, copy the example:

<Tabs items={['macOS/Linux', 'PowerShell']}>
  <Tab value="macOS/Linux">
    ```sh
    cp .env.example apps/web/.env.local
    ```
  </Tab>
  <Tab value="PowerShell">
    ```powershell
    Copy-Item .env.example apps/web/.env.local
    ```
  </Tab>
</Tabs>

With a [separate API](../cli/frontend-and-api.mdx), the CLI creates two files: `apps/web/.env.local` for the React + Vite frontend, from `.env.example`, and `apps/api/.env.local` for the API, from `apps/api/.env.example`. The API owns the database and the modules, so `DATABASE_URL` and the modules' variables, such as `REDIS_URL`, `SMTP_URL`, or `STRIPE_SECRET_KEY`, go in the API's file. The database commands read it there.

With a [mobile app](./mobile-app.mdx), the CLI also creates `apps/shell/.env.local`, from `apps/shell/.env.example`. It holds `WEB_URL`, the deployed website's `https://` address, which the app calls. The app's build also reads `apps/web/.env.local`, and the values in `apps/shell/.env.local` win.

With the [native app](./native-app.mdx), the CLI also creates `apps/mobile/.env.local`, from `apps/mobile/.env.example`. Expo builds its `EXPO_PUBLIC_*` values into the app, so they are public:

| Variable | Needed for | Details |
| --- | --- | --- |
| `EXPO_PUBLIC_API_URL` | Release builds, and a phone in development | Where the app sends its requests: the website's address, or the API's without a website. Blank in development, it means this computer's dev server, which the Android emulator reaches at `10.0.2.2` and the iOS simulator at `localhost`. |
| `EXPO_PUBLIC_DEV_SERVER_PORT` | Without a website | The port of that dev server: `3001`, the API's. With a website, it is 3000. |
| `EXPO_PUBLIC_SUPABASE_URL`, `EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY` | Supabase Auth | The same project's settings as the website's, or the API's without a website. [Sign-in](./native-app.mdx#sign-in) |

In a project [without a website](../cli/without-a-website.mdx), there is no `apps/web/.env.local`: `apps/api/.env.local` holds every variable, with `HOST=0.0.0.0` so that a phone on the same network reaches the API in development. With Better Auth, which then runs in the API, it also holds `BETTER_AUTH_SECRET` (at least 32 characters, which `pnpm check:env` checks) and `BETTER_AUTH_URL`, the API's public URL: `http://localhost:3001` in development.

The example points at your [local services](./local-services.mdx) and leaves provider keys blank, so the app builds and starts before anything is configured. Without local services, set at least `DATABASE_URL`:

```dotenv title="apps/web/.env.local"
DATABASE_URL=postgres://user:password@host:5432/app
```

## Variables [#variables]

A project only contains the variables of the modules it uses. Next.js and TanStack Start name a few of them differently, and React + Vite splits them between the frontend and the API:

<Tabs items={['Next.js', 'TanStack Start', 'React + Vite']} groupId="framework" persist>
  <Tab value="Next.js">
    | Variable | Needed for | Details |
    | --- | --- | --- |
    | `DATABASE_URL` | Required | PostgreSQL connection URL, such as a Supabase transaction pooler URL. |
    | `NEXT_PUBLIC_APP_URL` | Recommended | The app's origin. Defaults to `http://localhost:3000`. |
    | `NEXT_PUBLIC_SUPABASE_URL`, `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY` | Supabase Auth | [Authentication](./modules/auth.mdx) |
    | `CLIENT_IP_HEADER`, `TRUSTED_PROXY_HOPS` | Rate limits in production | Where the client's address is for your host (Starter v0.27.0 or newer): [Client addresses](./before-deploying.mdx#client-addresses) |
  </Tab>
  <Tab value="TanStack Start">
    | Variable | Needed for | Details |
    | --- | --- | --- |
    | `DATABASE_URL` | Required | PostgreSQL connection URL, such as a Supabase transaction pooler URL. |
    | `APP_URL` | Recommended | The app's origin. Defaults to `http://localhost:3000`. |
    | `SUPABASE_URL`, `SUPABASE_PUBLISHABLE_KEY` | Supabase Auth | [Authentication](./modules/auth.mdx) |
    | `CLIENT_IP_HEADER`, `TRUSTED_PROXY_HOPS` | Rate limits in production | Where the client's address is for your host (Starter v0.27.0 or newer): [Client addresses](./before-deploying.mdx#client-addresses) |
  </Tab>
  <Tab value="React + Vite">
    The frontend, in `apps/web/.env.local`:

    | Variable | Needed for | Details |
    | --- | --- | --- |
    | `API_URL` | Required | The API's address, `http://127.0.0.1:3001` locally. The dev server, `vite preview`, and the production server forward `/api` to it. |
    | `VITE_API_URL` | Optional | The API's public URL, for the browser to call it directly instead of through the frontend's `/api`. Leave it blank with Better Auth. |
    | `VITE_SUPABASE_URL`, `VITE_SUPABASE_PUBLISHABLE_KEY` | Supabase Auth | [Authentication](./modules/auth.mdx#a-frontend-and-its-api) |
    | `VITE_FIREBASE_API_KEY`, `VITE_FIREBASE_PROJECT_ID`, `VITE_FIREBASE_AUTH_DOMAIN`, `VITE_FIREBASE_AUTH_EMULATOR_URL` | Firebase | [Authentication](./modules/auth.mdx#a-frontend-and-its-api) |
    | `VITE_APPWRITE_ENDPOINT`, `VITE_APPWRITE_PROJECT_ID` | Appwrite | [Authentication](./modules/auth.mdx#a-frontend-and-its-api) |
    | `DATABASE_URL`, `BETTER_AUTH_SECRET`, `BETTER_AUTH_URL`, `BETTER_AUTH_REQUIRE_EMAIL_VERIFICATION` | Better Auth, which runs in the frontend's server | [Authentication](./modules/auth.mdx#a-frontend-and-its-api) |
    | `SMTP_URL` or `RESEND_API_KEY`, and `EMAIL_FROM` | Better Auth's emails, the same values as the API's | [Email](./modules/email.mdx#a-frontend-and-its-api) |
    | `CLIENT_IP_HEADER`, `TRUSTED_PROXY_HOPS` | Rate limits in production | Where the client's address is for your host; the server sends it on to the API (Starter v0.27.0 or newer): [Client addresses](./before-deploying.mdx#client-addresses) |
    | `MOBILE_ORIGINS` | A [mobile app](./mobile-app.mdx) | The app's origins, which the server answers with CORS: `capacitor://localhost,https://localhost` by default. |

    Vite compiles the `VITE_*` values into the build, so set them where the frontend is built: in production, as Docker build arguments or the platform's build variables. They are public; never put a secret in one.

    The API, in `apps/api/.env.local`:

    | Variable | Needed for | Details |
    | --- | --- | --- |
    | `DATABASE_URL` | Required | PostgreSQL connection URL. |
    | `DATABASE_URL_DIRECT` | Optional | [Pooled and direct connections](./database.mdx#pooled-and-direct-connections) |
    | `HOST`, `PORT` | Optional | Where the API listens: `127.0.0.1` and `3001` by default. The images set `HOST=0.0.0.0`. |
    | `FRONTEND_URL` | Recommended | The frontend's origin, the only one the API's CORS allows. Defaults to `http://localhost:3000`. |
    | `SUPABASE_URL`, `SUPABASE_PUBLISHABLE_KEY` | Supabase Auth | [Authentication](./modules/auth.mdx#a-frontend-and-its-api) |
    | `SUPABASE_SECRET_KEY` | Account deletion (Supabase) | [Authentication](./modules/auth.mdx#the-settings-page) |
    | `FIREBASE_PROJECT_ID`, `FIREBASE_API_KEY`, `FIREBASE_CLIENT_EMAIL`, `FIREBASE_PRIVATE_KEY`, `FIREBASE_AUTH_EMULATOR_HOST` | Firebase | [Authentication](./modules/auth.mdx#a-frontend-and-its-api) |
    | `APPWRITE_ENDPOINT`, `APPWRITE_PROJECT_ID` | Appwrite | [Authentication](./modules/auth.mdx#a-frontend-and-its-api) |
    | `APPWRITE_API_KEY` | Account deletion (Appwrite) | [Authentication](./modules/auth.mdx#the-settings-page) |
    | `BETTER_AUTH_URL` | Better Auth | The frontend's origin, where Better Auth answers `/api/auth`. |
    | `CLIENT_IP_HEADER`, `TRUSTED_PROXY_HOPS` | Rate limits in production | `TRUSTED_PROXY_HOPS=1` when only the frontend's server reaches the API (Starter v0.27.0 or newer): [Client addresses](./before-deploying.mdx#client-addresses) |
    | `APP_MINIMUM_VERSION`, `APP_LATEST_VERSION`, `APP_UPDATE_URL`, `APP_NEXT_MINIMUM_VERSION`, `APP_NEXT_MINIMUM_VERSION_FROM` | Apps installed on phones (optional) | What `/api/app-version` tells them (Starter v0.27.0 or newer; the announced minimum, and each one's `_IOS` and `_ANDROID` forms, from v0.29.0): updates of the [mobile app](./mobile-app.mdx#updates) and the [native app](./native-app.mdx#updates) |

    The other modules' variables go in the API's file too, with Hono or FastAPI: the rows of the table below from `REDIS_URL` to `SENTRY_TRACES_SAMPLE_RATE`. The React + Vite build doesn't upload Sentry source maps yet.
  </Tab>
</Tabs>

With Next.js and TanStack Start, the rest are the same for both frameworks. With React + Vite, the module variables are the API's:

| Variable | Needed for | Details |
| --- | --- | --- |
| `DATABASE_URL_DIRECT` | Optional | [Pooled and direct connections](./database.mdx#pooled-and-direct-connections) |
| `SUPABASE_SECRET_KEY` | Account deletion (Supabase) | [Authentication](./modules/auth.mdx) |
| `BETTER_AUTH_SECRET` | Better Auth | [Authentication](./modules/auth.mdx) |
| `BETTER_AUTH_REQUIRE_EMAIL_VERIFICATION` | Better Auth with email (optional) | [Authentication](./modules/auth.mdx) |
| `FIREBASE_PROJECT_ID`, `FIREBASE_API_KEY` | Firebase | [Authentication](./modules/auth.mdx) |
| `FIREBASE_CLIENT_EMAIL`, `FIREBASE_PRIVATE_KEY` | Firebase in production (the service account) | [Authentication](./modules/auth.mdx) |
| `FIREBASE_AUTH_EMULATOR_HOST` | Firebase in development only | [Authentication](./modules/auth.mdx) |
| `APPWRITE_ENDPOINT`, `APPWRITE_PROJECT_ID`, `APPWRITE_API_KEY` | Appwrite | [Authentication](./modules/auth.mdx) |
| `REDIS_URL` | Redis (optional) | [Cache and rate limits](./modules/cache.mdx) |
| `SMTP_URL`, `EMAIL_FROM` | SMTP email | [Email](./modules/email.mdx) |
| `RESEND_API_KEY`, `EMAIL_FROM` | Resend email | [Email](./modules/email.mdx) |
| `STORAGE_BUCKET`, `STORAGE_REGION`, `STORAGE_ENDPOINT`, `STORAGE_ACCESS_KEY_ID`, `STORAGE_SECRET_ACCESS_KEY`, `STORAGE_PUBLIC_URL` | S3-compatible storage | [File storage](./modules/storage.mdx) |
| `STORAGE_DIRECTORY` | S3-compatible storage in a local folder (`--infra local`) | [File storage](./modules/storage.mdx) |
| `SUPABASE_STORAGE_BUCKET` | Supabase Storage | [File storage](./modules/storage.mdx) |
| `STRIPE_SECRET_KEY`, `STRIPE_WEBHOOK_SECRET`, `STRIPE_PRICE_<PLAN>` | Payments | [Payments](./modules/payments.mdx) |
| `JOBS_WORKER`, `CRON_SECRET` | pg-boss or BullMQ (optional) | [Background jobs](./modules/jobs.mdx) |
| `INNGEST_DEV`, `INNGEST_EVENT_KEY`, `INNGEST_SIGNING_KEY` | Inngest | [Background jobs](./modules/jobs.mdx) |
| `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS`, `OTEL_SERVICE_NAME` | OpenTelemetry | [Observability](./modules/observability.mdx) |
| `SENTRY_DSN`, `SENTRY_ENVIRONMENT`, `SENTRY_TRACES_SAMPLE_RATE` | Sentry | [Observability](./modules/observability.mdx) |
| `SENTRY_AUTH_TOKEN`, `SENTRY_ORG`, `SENTRY_PROJECT` | Sentry source maps, at build time only | [Observability](./modules/observability.mdx#source-maps) |

`DATABASE_URL` must be a non-empty string for server environment validation. If you are only exploring the UI, a local placeholder URL works, but database operations fail until it points to a real PostgreSQL database.

## Start the app [#start-the-app]

```sh
pnpm dev
```

The app is available at [http://localhost:3000](http://localhost:3000), the liveness endpoint at `/api/health`, and the readiness endpoint, which also checks the database, at `/api/ready`.

With a separate API, `pnpm dev` starts the API too, on port 3001. The frontend forwards `/api` to it, so `/api/health` and `/api/ready` on port 3000 answer from the API. Without a website, `pnpm dev` starts the API alone: its liveness endpoint is [http://localhost:3001/api/health](http://localhost:3001/api/health).
