Next.js supports .env.local out of the box. By default, environment variables are only accessible in the Node.js environment (Server Components, API routes). To expose a variable to the browser, you must prefix it with NEXT_PUBLIC_ .
This is the golden rule of environment configuration: .env.local
Now that you understand the base .env file, its specialized counterpart, .env.local , plays a crucial role in the hierarchy. its specialized counterpart
If you are building a standard Node.js backend without a framework, Node does not load .env.local automatically. You will need to use a package like dotenv . .env.local
# .env.example PORT= STRIPE_SECRET_KEY=your_stripe_key_here DATABASE_URL= Use code with caution.