# You want to test the production build locally, but log errors to a local terminal DEBUG_MODE=true # You want to test against a locally running production-ready database container DATABASE_SECRET=local_secure_password_123 Use code with caution. The Resulting Behavior:
, the application looks for production variables. If you need to point your local machine to a live production database or a specific production API key—without committing those credentials to the repository— .env.local.production .env.local.production
A critical rule of web development is ensuring that private backend keys are never leaked to the user's browser. Frameworks handle this by looking at how variable keys are named. Client-Accessible Variables # You want to test the production build
: Global local overrides applied across all environments (except testing), never committed to Git. Frameworks handle this by looking at how variable
The framework expects a highly rigid naming convention. The correct syntax places the environment name ( production or development ) before the .local suffix, not after it. The Naming Anatomy
has a robust built-in environment variable system with clear precedence rules. It supports all the standard file names and uses the NODE_ENV variable to determine which environment files to load. One crucial distinction is that server-side variables are read at runtime, while NEXT_PUBLIC_* variables are embedded at build time and become static strings in the JavaScript bundle. If a NEXT_PUBLIC_* variable changes, you must rebuild the application; simply changing it in your hosting environment is not sufficient.