如何在 Heroku for Node 应用程序上设置环境变量并连接到 PostgreSQL 数据库? [英] How to set environment variables on Heroku for Node app and connect to the PostgreSQL database?

查看:35
本文介绍了如何在 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 中为所有人(谷歌、Facebook 等)设置它们还是只为数据库设置它们,因为我必须用 Heroku 创建一个?我是否将本地数据库的链接保留在我的开发文件中并单独链接到 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 CONFIG-NAME OF MY HEROKU DATABASE -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 https://dashboard-classic.heroku.com/apps/{your-app-name}/settings 并通过网络界面提供相同的变量,正如我在上面的评论中提到的那样

or you could use UI https://dashboard-classic.heroku.com/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 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆