src/lib/env.ts:4.
Quick Setup
Create a.env.local file in your project root:
Required Variables
Database
DATABASE_URL
DATABASE_URL
Type: Example providers:
string (required)PostgreSQL connection string for Prisma.Resonance uses Prisma Postgres with the PostgreSQL adapter. Any PostgreSQL 12+ database will work.
- Prisma Postgres (recommended)
- Neon
- Supabase
- Railway Postgres
Chatterbox TTS (Modal)
CHATTERBOX_API_URL
CHATTERBOX_API_URL
Type:
url (required)The deployed Modal endpoint URL for your Chatterbox TTS API.This URL is displayed after running
modal deploy chatterbox_tts.py. See Modal Deployment for setup instructions.CHATTERBOX_API_KEY
CHATTERBOX_API_KEY
Type: Generate a secure key:
string (required)API key for authenticating requests to the Chatterbox TTS endpoint.Clerk Authentication
CLERK_SECRET_KEY
CLERK_SECRET_KEY
Type: Find this in your Clerk Dashboard under API Keys.
string (required)Server-side Clerk secret key (starts with sk_).NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
Type:
string (required, client-side)Public Clerk key (starts with pk_).The
NEXT_PUBLIC_ prefix makes this variable accessible in browser code.NEXT_PUBLIC_CLERK_SIGN_IN_URL
NEXT_PUBLIC_CLERK_SIGN_IN_URL
Type:
string (required, client-side)Path to your sign-in page.NEXT_PUBLIC_CLERK_SIGN_UP_URL
NEXT_PUBLIC_CLERK_SIGN_UP_URL
Type:
string (required, client-side)Path to your sign-up page.Cloudflare R2 Storage
R2_ACCOUNT_ID
R2_ACCOUNT_ID
Type: Find this in the Cloudflare Dashboard sidebar under R2.
string (required)Your Cloudflare account ID.R2_ACCESS_KEY_ID
R2_ACCESS_KEY_ID
Type:
string (required)R2 API token access key ID.R2_SECRET_ACCESS_KEY
R2_SECRET_ACCESS_KEY
Type:
string (required)R2 API token secret access key.R2_BUCKET_NAME
R2_BUCKET_NAME
Type:
string (required)Name of your R2 bucket.Polar Billing
POLAR_ACCESS_TOKEN
POLAR_ACCESS_TOKEN
Type: Generate this in the Polar Dashboard under Settings → API Tokens.
string (required)Your Polar API access token.POLAR_SERVER
POLAR_SERVER
Type: Options:
enum (required)Polar environment mode.sandbox- Use for development (test card:4242 4242 4242 4242)production- Use for live payments
sandbox (defined in src/lib/env.ts:7)POLAR_PRODUCT_ID
POLAR_PRODUCT_ID
Type:
string (required)The ID of your Polar product with usage-based metering.Create a product in Polar Dashboard and attach a character-based meter for TTS billing.
Application
APP_URL
APP_URL
Type: Used for:
string (required)The base URL of your application.- Clerk redirect URLs (checkout success, billing portal)
- Polar webhook verification
- Email templates
Optional Variables
Development
SKIP_ENV_VALIDATION
SKIP_ENV_VALIDATION
Type: Defined in
boolean (optional)Skip environment variable validation during build.src/lib/env.ts:19NODE_ENV
NODE_ENV
Type:
enum (automatic)Set automatically by Node.js.Values:development- Local dev server (npm run dev)production- Production builds (npm run build && npm start)test- Testing environment
src/lib/db.ts:14 to prevent Prisma connection pooling in development.Validation
All environment variables are validated using Zod at application startup. If validation fails, the build will error with details about missing or invalid variables.src/lib/env.ts
Environment File Structure
Here’s a complete.env.local template:
.env.local
Security Best Practices
Rotate keys regularly
Update API keys and tokens periodically, especially after team member changes.
Troubleshooting
Validation errors at build time
https://) and is properly formatted.
Variables not loading
SKIP_ENV_VALIDATION not working
This variable must be set before the Next.js build process runs:Related Documentation
Database Setup
Prisma schema and migrations
Cloudflare R2
Object storage configuration
Clerk Auth
Authentication and organizations
Polar Billing
Usage-based billing setup