In my NextJS project, I'm looking to set up three different environments: development, staging, and production. Each environment requires specific variables to run properly. For development, I use a file named .env
, for production it's .env.production
, and for staging it's .env.staging
. Here's a snippet of my scripts:
"scripts": {
"dev": "next dev -p 3001",
"build": "next build",
"start": "next start",
},
To simulate the staging environment, I added this script:
"start:staging": "NODE_ENV=staging next dev -p 3001",
However, when I check
console.log(process.env.NODE_ENV, 'env variable');
, it still shows development
. What am I doing wrong and how can I ensure that I get the correct variables for each environment?