简体   繁体   中英

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?

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM