How to get local heroku app to connect to remote REDIS?
How to get local heroku app to connect to remote REDIS?
I am new to Heroku/Redis. I have created a basic node.js and express APP to which I have added a REDIS addon.
heroku addons:create heroku-redis:hobby-dev -a MyApp
I have an index.js
from which the server runs on port 5000
index.js
const express = require('express')
const path = require('path')
const PORT = process.env.PORT || 5000
const client = require('redis').createClient(process.env.REDIS_URL);
express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index'))
.listen(PORT, () => console.log(`Listening on ${ PORT }`))
My repo is connected to my personal github from Heroku where the app runs fine, but whenever I try to run it locally it seems it tries to connect to REDIS locally so I have the following error when running my node command (node index.js):
Listening on 5000
events.js:183
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
I am very new to this but am presuming that the environment is wrong: process.env.REDIS_URL
, how can I connect straight to the Heroku cloud instead of my local one?
process.env.REDIS_URL
Thanks
1 Answer
1
Copy Heroku config vars to your local .env file
heroku config -s > .env
Run your app locally using the Heroku local command
heroku local
See more details at https://devcenter.heroku.com/articles/heroku-local
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.