Search code examples
node.jsherokuenvironment-variablesgitignoreapi-key

How to use .env file while deploying my app?


I want to deploy my app using Heroku but I have kept my API keys in .env file which will be ignored by .gitignore file while pushing to Heroku and after deploying my app on Heroku, it is no longer able to read my API keys and app crashes? What to do in this case? How to use it correctly?


Solution

  • If your not storing your .env file in your git repository (which is absolutely the correct thing to do) then you need to manually configure the .env file once you deploy it.

    In the instance of Heroku you can set Config Vars:

    Configuration and Config Vars

    If you do it that way I believe you have to access the vars in a different manor to env values but it has a local mode so that shouldn't be a problem.