Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Next js run different env variables

I am using NextJS. I need to create 3 type of environments:

  1. development
  2. staging
  3. production

I need to run on each env. specific variables.
For development i have .env, for productiuon i have .env.production and for staging i have .env.staging. My scrips looks like this:

"scripts": {
  "dev": "next dev -p 3001",
  "build": "next build",
  "start": "next start",
},

For simulating staging env. i created this:

"start:staging": "NODE_ENV=staging next dev -p 3001",

But when i check console.log(process.env.NODE_ENV, 'env variable'); i get development.
What i do wrong and how to get the proper variables?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are running next dev wich makes your application runs with developmento mode, thats why you get development.

Take a look at https://nextjs.org/docs/api-reference/cli#development

If you whant to use next.js build in env features you have the follow their docs https://nextjs.org/docs/basic-features/environment-variables#default-environment-variables.Basically you can have 3 environment files, local, development and production and they will be used when running the application with next dev and next start. The local env files always overrides the others, do not commit it to your project or your dev and production files wont be used.

If you want to do the exactly thing you said (development, staging and production) you will have to override next env by yourself. You can achieve this using dotenv.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!