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

152
Vistas
Different .env content for development and production

I have a .env file (I am using next.js and node.js, where each have their own .env), where some content are different for development and deployment.

For development:

DOMAIN_URL=https://localhost:3000
GOOGLE_CLIENT_ID='abc'

For deployment:

DOMAIN_URL=https://www.example.com
GOOGLE_CLIENT_ID='def'

I hope to make it easy by setting a flag say DEV_FLAG=dev or DEV_FLAG=production and according to the DEV_FLAG the .env can be set accordingly,

  1. but how to use if condition in .env file?
  2. Or if there is a better way to set the .env for different context?
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

.env file is not meant to be commited in repo. It is meant to be added before running app. It should be ignored by VCS by adding .env line to .gitignore or .hgignore file.

.env file contains potentially secret values and you don't want to have them in repo for everyone to see.

You can commit example.env for deployers to see which env variables are available. Deployer/DevOp will run cp example.env .env, then edit .env file and run application.

You can commit default.env and load it in application before loading .env file for some sane not secret default values for tests or some generic (localhost) deploy environment.

But .env file should be original in each deploy.

You could set some flag DEV_FLAG=dev or DEV_FLAG=prod and in application change some behaviour based on its value, but generally I would not recommend it because it hides consequences.

Maybe you are developing on one pc and want to switch .env values. You can have more lines in file and comment them out as needed or you can have prod.env or local.env files and cp local.env .env as needed while having them ignored in .gitignore.

More about this topic you can read here: https://www.12factor.net/config

about 4 years ago · Santiago Gelvez 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