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

287
Visualizações
How to hide an API key in the public folder of node.js when deploying to heroku?

I am serving public HTML and JavaScript files through the public folder of node.js with the help of app.use(express.static('public')); in my server.js file.

The public folder has an index.js. Here I have an api key for fetching a Map from mapbox. I added the api key into a config.js file within the public folder, and added config.js to the git ignore file inside the public folder. This doesn't work when I deploy the code on heroku.

How do I successfully deploy the code on Heroku without leaking the Map API key present in the public folder of node.js? I know that API's need to be on the server side, but should I do the same for the map API?

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

0

npm install dotenv

create a .env file in your project

put API key there

In your server file initial dotenv dependencies

And use it where you want

On Heroku go to settings and reveal config vars and add your .env variable there with value and that would be it

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