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

258
Visualizações
Env variables: using custom-enviroment-variables.json, what is the right way to define app secrets

I am using the 'config' module in my node.js app and I was wondering how to implement environment variables for different environments (dev/prod) based on NODE_ENV.

Say I'm setting the NODE_ENV to production. I have a 'config' folder with 4 JSON files: custom-environment-variables.json, production.json, development.json and default.json.

production.json:

{
"name":"Cost Manager Application - Production",
"db":"prod_db_key"
}

development.json:

{
    "name":"Cost Manager Application - Development",
    "db":"dev_db_key"
}

default.json:

{
   "name":"Cost Manager Application",
   "appPrivateKey":"",
   "db": "mongodb://localhost:27017"
}

Now, I want to store both my prod and dev db strings in env variables, named prod_db_key and dev_db_key and I know that that's what the custom-environment-variables.json is for. However, I do not want to name these keys differently in the custom-environment-variables.json file because I want to be able to use 'db' from index.js:

console.log(config.get('db'));

And then based on the results of

 config.util.getEnv('NODE_ENV'));

Use the right environment variable (prod_db_key/dev_db_key) under "db".

The things is, I do not want to explicitly ask for prod_db_key or dev_db_key from index.js, that's the whole point. Otherwise, I would have just configured two pairs of key and value in the custom-environment-variables.json file. Does it make sense?

Thanks in advance...

about 4 years ago · Juan Pablo Isaza
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