.env · generator · Next.js
Next.js .env Generator
Next.js reads .env.local automatically — no import needed. This generator produces a complete file for the most common Next 15 stack: NextAuth for auth, Supabase for data, Stripe for payments.
.env for Next.js · 10 keys
NEXT_PUBLIC_SITE_URL=http://localhost:3000 DATABASE_URL=postgresql://user:password@localhost:5432/mydb NEXTAUTH_URL=http://localhost:3000 NEXTAUTH_SECRET=VW6-qNsqs8drl5aX7OlNlCKtogbcMSLNGUCFoJamEHT_3ZUw NEXT_PUBLIC_SUPABASE_URL= NEXT_PUBLIC_SUPABASE_ANON_KEY= SUPABASE_SERVICE_ROLE_KEY= STRIPE_SECRET_KEY=sk_test_ STRIPE_WEBHOOK_SECRET=whsec_ NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_
Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.
How to use this .env in Next.js
- 1.Paste the output into .env.local in your project root.
- 2.Keep NEXT_PUBLIC_ prefixes — those variables are exposed to the browser.
- 3.Restart the dev server after adding or changing variables.
- 4.Add all the same keys in your Vercel (or host) project settings for production.
Gotchas
- ⚠Variables without NEXT_PUBLIC_ are server-only. Accessing them in a client component returns undefined.
- ⚠.env.local is loaded in every env except during tests. Use .env.test for test overrides.
- ⚠Next.js inlines NEXT_PUBLIC_ variables at build time — changing them requires a rebuild.
Common keys explained
NEXT_PUBLIC_SITE_URLCanonical URL — used for absolute redirects, OG tags, sitemaps.
DATABASE_URLPostgres or Supabase connection string.
NEXTAUTH_SECRETRequired. Sign JWTs + encrypt session cookies.
NEXT_PUBLIC_SUPABASE_URLYour Supabase project URL. Safe to expose.
NEXT_PUBLIC_SUPABASE_ANON_KEYPublic Supabase key. Safe to expose — RLS protects data.
SUPABASE_SERVICE_ROLE_KEYServer-only admin key. Never prefix with NEXT_PUBLIC_.
STRIPE_SECRET_KEYServer-only Stripe secret. sk_test_ for dev, sk_live_ for prod.
STRIPE_WEBHOOK_SECRETVerifies Stripe webhook signatures. Rotate per environment.
Related tools
Other stacks
Node.js .env
/env-generator/nodejs
Django .env
/env-generator/django
Ruby on Rails .env
/env-generator/rails
React (Vite) .env
/env-generator/react
Python (FastAPI / Flask) .env
/env-generator/python
Go .env
/env-generator/go
Docker Compose .env
/env-generator/docker
Kubernetes .env
/env-generator/kubernetes
Stripe .env
/env-generator/stripe
Firebase .env
/env-generator/firebase
Supabase .env
/env-generator/supabase
OpenAI .env
/env-generator/openai
Laravel .env
/env-generator/laravel