简体   繁体   English

部署我的应用程序时如何使用.env 文件?

[英]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? 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应用程序崩溃? 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.如果您没有将 your.env 文件存储在 git 存储库中(这绝对是正确的做法),那么您需要在部署后手动配置 .env 文件。

In the instance of Heroku you can set Config Vars:在 Heroku 的实例中,您可以设置 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.如果你这样做,我相信你必须以不同的庄园访问 vars 到 env 值,但它有一个本地模式,所以这不应该是一个问题。

You have to specify all the API keys in your START script in "package.json".您必须在“package.json”中的 START 脚本中指定所有 API 键。 Like below如下所示

"start": "MONGO_USER=abcis app.js" “开始”:“MONGO_USER=abcis app.js”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在网站上使用.ENV文件 - How to use an .ENV file with a website 尝试在我的项目中使用 a.env 文件 - Trying to use a .env file inside my project 如果它应该在 mac 上使用 test.env 或 dev.env,我如何告诉我的 node/express 应用程序? - how do i tell my node/ express app if it should use test.env or dev.env on mac? 如果我不应该提交.env,我的生产Heroku应用程序如何知道要使用的秘密密钥? - How does my production Heroku app know what secret key to use if I am not supposed to commit .env? 将应用程序部署到 Heroku,ENV 变量不工作 - Deploying app to Heroku, ENV variables not wokring 如何在我的Google App Engine app.yaml文件中为我的母版设置不同的NODE_ENV并开发Git分支? - How to set a different NODE_ENV for my master and develop Git branches in my Google App Engine app.yaml file? NestJS - 如何在主应用程序模块文件中使用 .env 变量进行数据库连接 - NestJS - How to use .env variables in main app module file for database connection 如何将路径添加到.env 文件并使用它? - How to add path to .env file and use it? 我如何在节点中使用环境文件 - How can i use env file in node 部署我的应用程序的新版本时丢失的请求 - Lost requests while deploying new versions of my app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM