如何在Heroku for Node应用程序上设置环境变量并连接到PostgreSQL数据库?

编程入门 行业动态 更新时间:2024-10-24 21:32:21
本文介绍了如何在Heroku for Node应用程序上设置环境变量并连接到PostgreSQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道堆栈溢出有相同/相似的问题,我也阅读了文档-我还是什么都不懂-如何设置这些变量并在哪里!设置它们.

I know there are the same/similar questions on stack overflow and I have read the documentation too-I just still don't understand ANYTHING- how to set those variables and WHERE!! to set them.

我的env/production.js文件:

My env/production.js file:

module.exports = { "DATABASE_URI": process.env.DATABASE_URI, "SESSION_SECRET": process.env.SESSION_SECRET, "TWITTER": { "consumerKey": process.env.TWITTER_CONSUMER_KEY, "consumerSecret": process.env.TWITTER_CONSUMER_SECRET, "callbackUrl": process.env.TWITTER_CALLBACK }, "FACEBOOK": { "clientID": process.env.FACEBOOK_APP_ID, "clientSecret": process.env.FACEBOOK_CLIENT_SECRET, "callbackURL": process.env.FACEBOOK_CALLBACK_URL }, "GOOGLE": { "clientID": process.env.GOOGLE_CLIENT_ID, "clientSecret": process.env.GOOGLE_CLIENT_SECRET, "callbackURL": process.env.GOOGLE_CALLBACK_URL }, "LOGGING": true };

在我的env/development.js文件中,设置变量(链接到我的PostgreSQL/localhost/xxx).因为必须使用Heroku创建一个数据库,我是否需要在Heroku中为所有数据库(Google,Facebook等)设置它们,还是只为数据库设置它们?我是否将指向本地数据库的链接保留在开发文件中,并单独链接至Heroku数据库?

In my env/development.js file I set the variables (linked to my PostgreSQL/localhost/xxx). Do I need to set them in Heroku for all (Google, Facebook etc.) or just for the database, since I had to create one with Heroku? Do I leave the link to my local database in my development file and link to the Heroku database separately?

我什至不知道我是否应该从命令行执行此操作?在文档中说:Heroku config:get CONFIG-VAR-NAME -s>>.env所以是Heroku config:get我的HEROKU数据库的配置名称-s>>.env 吗?

I don't even know if I am supposed to do it from my command line?! In the documentation it says: Heroku config:get CONFIG-VAR-NAME -s >> .env so would it be Heroku config:get CONFIG-NAME OF MY HEROKU DATABASE -s >> .env ?

我是第一次部署,真是太困惑了!帮助:)

I'm deploying for the first time and so confused! Help :)

推荐答案

根据文档您可以使用 heroku CLI

$ heroku config:set DATABASE_URI=database_uri_here $ heroku config:set SESSION_SECRET=session_secret ... and so on for each variable,

,或者您可以使用UI dashboard-classic.heroku/apps/ {your-app-name}/settings并通过网络界面提供相同的变量,如我在上面的评论中所述

or you could use UI dashboard-classic.heroku/apps/{your-app-name}/settings and provide same variables via web interface, as I mention in above comment

NODE_ENV = production 未被 heroku 特殊对待,因此您需要提供它以及任何其他env变量

NODE_ENV=production is not treated specially by heroku, so you do need to provide it as well as any other env variable

ps:严格来说,这个问题并不真正属于SO,因为它与编程无关.也许需要将其移至 SU

更多推荐

如何在Heroku for Node应用程序上设置环境变量并连接到PostgreSQL数据库?

本文发布于:2023-10-23 13:45:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   应用程序   环境变量   数据库   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!