.env.local.production [better]

# .env.production API_URL=https://api.myapp.com API_URL=http://localhost:3001/mock-api

Visit /api/debug and look for your variable. In next.config.js : .env.local.production

Do not use both. Use .env.local for development mode. Use .env.production.local exclusively for production mode debugging. Part 7: Debugging – Is My File Being Loaded? It is notoriously difficult to know which env file is active. Here is how to check. Method 1: Dump the Config (Next.js) Create a file pages/api/debug.js : Here is how to check

# .github/workflows/deploy.yml - name: Create .env.production.local run: | echo "BUILD_CACHE_TOKEN=$ secrets.CI_TOKEN " > .env.production.local npm run build You are testing a production build but have a limited API key for Stripe or OpenAI that fails on high volume. Override it with a local test key without touching the real .env.production . Part 5: Security Nightmare – Do NOT Commit This File This section cannot be stressed enough. but you want to test locally.

Now your production build pulls assets locally. GitHub Actions or GitLab CI often run next build in a production environment but need a build-time secret that differs from runtime.

At first glance, this file name looks like a typo or a conspiracy. However, for developers using frameworks like Next.js, Gatsby, or Vite, this specific naming convention solves a critical pain point:

require('dotenv').config( path: '.env.production.local' ); You must manually handle the loading order. Case 1: Bypassing CDN Caching for Debugging You have a production app behind a CloudFront CDN. You suspect the CDN is caching old assets. You cannot disable the CDN globally, but you want to test locally.