Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda