Smile001
Smile001

Reputation: 167

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?

Upvotes: 3

Views: 8122

Answers (2)

Dharmik Patel
Dharmik Patel

Reputation: 1201

You have to specify all the API keys in your START script in "package.json". Like below

"start": "MONGO_USER=abcis app.js"

Upvotes: 0

UrbanwarfareStudios
UrbanwarfareStudios

Reputation: 360

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.

Upvotes: 4

Related Questions