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

262
Vistas
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 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