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

587
Visualizações
Why i should not use dotenv in production mode?

Why I should not use dotenv in production mode ?

I saw the following code on some websites. But I did not understand why they are doing this condition check.

if (process.env.NODE_ENV !== 'production') {
  require('dotenv').config();
}
console.log('Bla is :', process.env.Bla);(*)

let assume that the output of the line(*) in not production mode is-> Bla is : Bla

what is the output of line (*) if the NODE_ENV is production? (According to my knowledge I think it will be undefined )

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Because in production, you might want to set the environment variables directly into your virtual machine, as you might not have ssh access and you can't push .env file to your version control. In my case I'm using heroku free tier and I can't ssh to create a .env file. So I set my environment variables manually in the Config Vars settings.

Heroku vm settings

over 4 years ago · Santiago Trujillo Relatório

0

Complementing the other answers, you would also create a security issue. You would be versioning (commiting to git) informations like database connections, tokens, and passwords. In this case everyone who access the code, would be able to connect to production resources.

To solve this, on production you create the env variables directly on the instance you are running the code.

over 4 years ago · Santiago Trujillo Relatório

0

The idea behind this is that dotenv is generally used on a developer workstation. It is a way of using a flat file (usually named ".env") to override environment files. The reason you dont use it in production is that in production you would usually be running the application in a docker container or a dedicated server, either of which, you wouldnt need to worry about setting conflicting environment variables.

To answer the actual question, the output for that line in this case would be whatever that local environment variable is set to. If its not set, it would just be undefined.

over 4 years ago · Santiago Trujillo 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