Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda