Skip to content

Set Up Environment Variables and the Database

Install dependencies with pnpm, fill in the Zod-validated environment variables in apps/web/.env and create the PostgreSQL schema for your Nuxt app.

Install dependencies

Run all commands from the repository root:

pnpm install

This also runs nuxt prepare in apps/web, which generates the types.

Setup environment variables

Copy apps/web/.env.example to apps/web/.env and fill in the values. The Nuxt CLI reads this file in development and during the build.

cp apps/web/.env.example apps/web/.env

Every layer declares its environment variables as Zod schemas in the runtimeConfig of its nuxt.config.ts. When a required value is missing, the server refuses to start and lists the missing values (error NUXT_E8014). At runtime only the type, whether a value is required and enum values are checked, not refinements like .min() or .url().

Required environment variables:

  • NUXT_BETTER_AUTH_SECRET - Secret for better-auth, at least 32 random characters (e.g. openssl rand -base64 32)
  • NUXT_PRIVATE_DATABASE_URL - PostgreSQL connection string
  • NUXT_PUBLIC_BASE_URL - Your app URL (e.g., http://localhost:9009 for local dev). better-auth uses it as its base URL.
  • NUXT_PRIVATE_POLAR_ACCESS_TOKEN - Polar access token
  • NUXT_PRIVATE_EMAIL_CONTACT - Address that receives contact form submissions
  • NUXT_PRIVATE_FROM_EMAIL - Sender address of all emails

Optional:

  • NUXT_PRIVATE_POLAR_ORGANIZATION_ID - Your Polar organization ID
  • NUXT_PRIVATE_POLAR_SERVER - sandbox (default) or production
  • OAuth credentials for social login (Google, GitHub), see Authentication
  • Email provider settings, see Emails
  • Storage settings, see Images
Never read process.env in app code. Add new values as Zod schemas to the nuxt.config.ts of the layer that owns them and to apps/web/.env.example, then read them with useRuntimeConfig().

Create database schema

Apply the database migrations:

pnpm db:migrate

The migrations are part of the repository. Run pnpm db:generate only after you change a schema file, see Database.

Start the development server

Start the development server for the web app:

pnpm dev

You can now access your app at http://localhost:9009.

Polar

Nuxt Starter Kit uses Polar to accept payments, see Payments for more information.

This starter kit is designed to support subscriptions (free & Pro) and lifetime deals. You should configure three products in Polar:

  • Pro Plan (yearly subscription)
  • Pro Plan (monthly subscription)
  • Lifetime Deal (one-time payment)
Any other product constellation needs adjustments in the apps/web/layers/payment layer and other parts of the codebase.