'Can't connect Redis with Heroku

I'm kinda new but what I did so far was the following:

  1. Created Redis cloud account, set it up on RedisInsight on my computer.
  2. Heroku was fully deployed, went to my account and set the Redis Vars (URL and password).
  3. Added requested code into App.js file, everything seems to be working fine on that side (localhost).

When I try to open the app it shows an error, logs are at the bottom (pretty long).

Thanks a lot for your help guys!


App.js Redis code:

const redis = require('redis')
const client =
  process.env.NODE_ENV === 'production'
    ? redis.createClient(
        `redis://${process.env.REDIS_ENDPOINT_URI.replace(
          /^(redis\:\/\/)/,
          ''
        )}`,
        { password: process.env.REDIS_PASSWORD }
      )
    : redis.createClient()
const redisStore = require('connect-redis')(session)

Heroku error logs when I open the app:

2022-05-13T19:51:27.759246+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
2022-05-13T19:51:27.759247+00:00 app[web.1]: at node:internal/main/run_main_module:17:47
2022-05-13T19:51:28.143822+00:00 heroku[web.1]: Process exited with status 1
2022-05-13T19:51:28.256150+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-13T19:51:28.268614+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-13T19:51:30.198848+00:00 heroku[web.1]: Starting process with command `node app.js`
2022-05-13T19:51:31.028025+00:00 app[web.1]: /app/app.js:8
2022-05-13T19:51:31.028036+00:00 app[web.1]: `redis://${process.env.REDIS_ENDPOINT_URI.replace(
2022-05-13T19:51:31.028037+00:00 app[web.1]: ^
2022-05-13T19:51:31.028037+00:00 app[web.1]:
2022-05-13T19:51:31.028038+00:00 app[web.1]: TypeError: Cannot read properties of undefined (reading 'replace')
2022-05-13T19:51:31.028038+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:8:51)
2022-05-13T19:51:31.028039+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-13T19:51:31.028039+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-13T19:51:31.028039+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-13T19:51:31.028040+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-13T19:51:31.028040+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
2022-05-13T19:51:31.028040+00:00 app[web.1]: at node:internal/main/run_main_module:17:47
2022-05-13T19:51:31.138917+00:00 heroku[web.1]: Process exited with status 1
2022-05-13T19:51:31.295507+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-13T19:52:38.914833+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=melon-wallet2.herokuapp.com request_id=c97d9486-10ca-4aa4-80e5-ea0460e3edff fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https
2022-05-13T19:52:39.265838+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=melon-wallet2.herokuapp.com request_id=05aadd1d-c48c-4922-a181-a9ca6725b85f fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https
2022-05-13T19:55:07.389539+00:00 app[api]: Running release v4 commands by user [email protected]
2022-05-13T19:55:07.389539+00:00 app[api]: Attach REDISTOGO (@ref:redistogo-animate-59525) by user [email protected]
2022-05-13T19:55:07.406750+00:00 app[api]: @ref:redistogo-animate-59525 completed provisioning, setting REDISTOGO_URL. by user [email protected]
2022-05-13T19:55:07.406750+00:00 app[api]: Release v5 created by user [email protected]
2022-05-13T19:55:07.926317+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-13T19:55:09.958180+00:00 heroku[web.1]: Starting process with command `node app.js`
2022-05-13T19:55:11.941875+00:00 app[web.1]: /app/app.js:8
2022-05-13T19:55:11.941893+00:00 app[web.1]: `redis://${process.env.REDIS_ENDPOINT_URI.replace(
2022-05-13T19:55:11.941894+00:00 app[web.1]: ^
2022-05-13T19:55:11.941894+00:00 app[web.1]:
2022-05-13T19:55:11.941894+00:00 app[web.1]: TypeError: Cannot read properties of undefined (reading 'replace')
2022-05-13T19:55:11.941895+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:8:51)
2022-05-13T19:55:11.941895+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-13T19:55:11.941896+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-13T19:55:11.941896+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-13T19:55:11.941896+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-13T19:55:11.941897+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
2022-05-13T19:55:11.941897+00:00 app[web.1]: at node:internal/main/run_main_module:17:47
2022-05-13T19:55:12.075753+00:00 heroku[web.1]: Process exited with status 1
2022-05-13T19:55:12.134330+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-13T19:57:43.774299+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=melon-wallet2.herokuapp.com request_id=9bd918cd-452b-427f-b03a-e96918d71b71 fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https
2022-05-13T19:57:44.104076+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=melon-wallet2.herokuapp.com request_id=97303648-234e-4c85-9a9f-928b65c66306 fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https
2022-05-13T21:00:39.064689+00:00 app[api]: Set REDISTOGO_URL config vars by user [email protected]
2022-05-13T21:00:39.064689+00:00 app[api]: Release v6 created by user [email protected]
2022-05-13T21:00:39.739909+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-13T21:00:41.814381+00:00 heroku[web.1]: Starting process with command `node app.js`
2022-05-13T21:00:44.273666+00:00 app[web.1]: /app/app.js:8
2022-05-13T21:00:44.273676+00:00 app[web.1]: `redis://${process.env.REDIS_ENDPOINT_URI.replace(
2022-05-13T21:00:44.273677+00:00 app[web.1]: ^
2022-05-13T21:00:44.273677+00:00 app[web.1]:
2022-05-13T21:00:44.273678+00:00 app[web.1]: TypeError: Cannot read properties of undefined (reading 'replace')
2022-05-13T21:00:44.273678+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:8:51)
2022-05-13T21:00:44.273679+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-13T21:00:44.273679+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-13T21:00:44.273679+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-13T21:00:44.273679+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-13T21:00:44.273680+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
2022-05-13T21:00:44.273680+00:00 app[web.1]: at node:internal/main/run_main_module:17:47
2022-05-13T21:00:44.396976+00:00 heroku[web.1]: Process exited with status 1
2022-05-13T21:00:44.495394+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-13T21:00:44.502352+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-13T21:00:46.426417+00:00 heroku[web.1]: Starting process with command `node app.js`
2022-05-13T21:00:47.843307+00:00 app[web.1]: /app/app.js:8
2022-05-13T21:00:47.843336+00:00 app[web.1]: `redis://${process.env.REDIS_ENDPOINT_URI.replace(
2022-05-13T21:00:47.843337+00:00 app[web.1]: ^
2022-05-13T21:00:47.843337+00:00 app[web.1]:
2022-05-13T21:00:47.843338+00:00 app[web.1]: TypeError: Cannot read properties of undefined (reading 'replace')
2022-05-13T21:00:47.843338+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:8:51)
2022-05-13T21:00:47.843338+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-13T21:00:47.843339+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-13T21:00:47.843339+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-13T21:00:47.843339+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-13T21:00:47.843340+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
2022-05-13T21:00:47.843340+00:00 app[web.1]: at node:internal/main/run_main_module:17:47
2022-05-13T21:00:47.956678+00:00 heroku[web.1]: Process exited with status 1
2022-05-13T21:00:48.021109+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-13T21:00:58.509247+00:00 app[api]: Release v7 created by user [email protected]
2022-05-13T21:00:58.509247+00:00 app[api]: Set REDIS_PASSWORD config vars by user [email protected]
2022-05-13T21:00:58.777609+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-13T21:01:00.701117+00:00 heroku[web.1]: Starting process with command `node app.js`
2022-05-13T21:01:01.476887+00:00 app[web.1]: /app/app.js:8
2022-05-13T21:01:01.476896+00:00 app[web.1]: `redis://${process.env.REDIS_ENDPOINT_URI.replace(
2022-05-13T21:01:01.476899+00:00 app[web.1]: ^
2022-05-13T21:01:01.476900+00:00 app[web.1]:
2022-05-13T21:01:01.476900+00:00 app[web.1]: TypeError: Cannot read properties of undefined (reading 'replace')
2022-05-13T21:01:01.476901+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:8:51)
2022-05-13T21:01:01.476901+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-13T21:01:01.476901+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-13T21:01:01.476902+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-13T21:01:01.476902+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-13T21:01:01.476902+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
2022-05-13T21:01:01.476903+00:00 app[web.1]: at node:internal/main/run_main_module:17:47
2022-05-13T21:01:01.596278+00:00 heroku[web.1]: Process exited with status 1
2022-05-13T21:01:01.708740+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-13T21:01:43.491184+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=melon-wallet2.herokuapp.com request_id=763fa606-9697-4055-aa6c-85296151b82f fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https
2022-05-13T21:01:43.856882+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=melon-wallet2.herokuapp.com request_id=7e0a98b6-b9d4-4c53-8906-6fc95b44fb81 fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https
2022-05-13T21:01:53.011981+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=melon-wallet2.herokuapp.com request_id=5da051b1-0e5c-4f1b-aa68-25f50fc9d665 fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https
2022-05-13T21:01:53.303822+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=melon-wallet2.herokuapp.com request_id=9c8605cf-8194-4cec-bbad-d6dc6e9dc76e fwd="104.219.179.22" dyno= connect= service= status=503 bytes= protocol=https


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source