Next.js loads .env.local automatically. To keep your secrets safe, Next.js follows one strict rule:
- Variables without a prefix (like
DATABASE_URLorSTRIPE_SECRET_KEY) are only available on the server. - Variables starting with
NEXT_PUBLIC_(likeNEXT_PUBLIC_SITE_URL) are bundled into browser JavaScript—never put private keys there!
ADVERTISEMENT