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

209
Visualizações
Is there a way to load a .json configuration file and automatically substitute environment variables?

I'm a little new to the javascript ecosystem, so apologies if I'm asking the question wrong.

I'm working on a legacy project that loads configuration files from .json files. In those .json files there are variables that need to be substituted with environment variables.

For example config.json:

{
  "database": {
    "host": "%DBHOST%",
    "port": "%DBPORT%"
  }
}

In the legacy code, there are complicated startup scripts that use sed to do variable substitution. I'm moving the project into docker and would much rather define DBHOST/DBPORT etc in the docker definitions and have it magically update the configuration. Right now, I just have docker running a script that does the sed operation which works, but this feels clunky. Is there a way I can tell node to load the .json file and automatically substitute the %VAR% blocks with an environment variable if there is a match?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

With NodeJS you can load an environment variable like this:

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