.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
Customize →
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. 1.Paste the output into .env.local in your project root.
  2. 2.Keep NEXT_PUBLIC_ prefixes — those variables are exposed to the browser.
  3. 3.Restart the dev server after adding or changing variables.
  4. 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_URL

Canonical URL — used for absolute redirects, OG tags, sitemaps.

DATABASE_URL

Postgres or Supabase connection string.

NEXTAUTH_SECRET

Required. Sign JWTs + encrypt session cookies.

NEXT_PUBLIC_SUPABASE_URL

Your Supabase project URL. Safe to expose.

NEXT_PUBLIC_SUPABASE_ANON_KEY

Public Supabase key. Safe to expose — RLS protects data.

SUPABASE_SERVICE_ROLE_KEY

Server-only admin key. Never prefix with NEXT_PUBLIC_.

STRIPE_SECRET_KEY

Server-only Stripe secret. sk_test_ for dev, sk_live_ for prod.

STRIPE_WEBHOOK_SECRET

Verifies Stripe webhook signatures. Rotate per environment.

Related tools

Other stacks