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

294
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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