title: Can't connect Redis with Heroku
body: <p>I'm kinda new but what I did so far was the following:</p>
  <ol>
  <li>Created Redis cloud account, set it up on RedisInsight on my computer.</li>
  <li>Heroku was fully deployed, went to my account and set the Redis Vars (URL and password).</li>
  <li>Added requested code into App.js file, everything seems to be working fine on that side (localhost).</li>
  </ol>
  <p>When I try to open the app it shows an error, logs are at the bottom (pretty long).</p>
  <p>Thanks a lot for your help guys!</p>
  <hr />
  <p><strong>App.js Redis code:</strong></p>
  <pre><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)
  </code></pre>
  <p><strong>Heroku error logs when I open the app:</strong></p>
  <pre><code>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.&lt;anonymous&gt; (/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=&quot;App crashed&quot; method=GET path=&quot;/&quot; host=melon-wallet2.herokuapp.com request_id=c97d9486-10ca-4aa4-80e5-ea0460e3edff fwd=&quot;104.219.179.22&quot; dyno= connect= service= status=503 bytes= protocol=https
  2022-05-13T19:52:39.265838+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/favicon.ico&quot; host=melon-wallet2.herokuapp.com request_id=05aadd1d-c48c-4922-a181-a9ca6725b85f fwd=&quot;104.219.179.22&quot; dyno= connect= service= status=503 bytes= protocol=https
  2022-05-13T19:55:07.389539+00:00 app[api]: Running release v4 commands by user alan_ps@hotmail.com
  2022-05-13T19:55:07.389539+00:00 app[api]: Attach REDISTOGO (@ref:redistogo-animate-59525) by user alan_ps@hotmail.com
  2022-05-13T19:55:07.406750+00:00 app[api]: @ref:redistogo-animate-59525 completed provisioning, setting REDISTOGO_URL. by user alan_ps@hotmail.com
  2022-05-13T19:55:07.406750+00:00 app[api]: Release v5 created by user alan_ps@hotmail.com
  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.&lt;anonymous&gt; (/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=&quot;App crashed&quot; method=GET path=&quot;/&quot; host=melon-wallet2.herokuapp.com request_id=9bd918cd-452b-427f-b03a-e96918d71b71 fwd=&quot;104.219.179.22&quot; dyno= connect= service= status=503 bytes= protocol=https
  2022-05-13T19:57:44.104076+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/favicon.ico&quot; host=melon-wallet2.herokuapp.com request_id=97303648-234e-4c85-9a9f-928b65c66306 fwd=&quot;104.219.179.22&quot; 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 alan_ps@hotmail.com
  2022-05-13T21:00:39.064689+00:00 app[api]: Release v6 created by user alan_ps@hotmail.com
  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.&lt;anonymous&gt; (/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.&lt;anonymous&gt; (/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 alan_ps@hotmail.com
  2022-05-13T21:00:58.509247+00:00 app[api]: Set REDIS_PASSWORD config vars by user alan_ps@hotmail.com
  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.&lt;anonymous&gt; (/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=&quot;App crashed&quot; method=GET path=&quot;/&quot; host=melon-wallet2.herokuapp.com request_id=763fa606-9697-4055-aa6c-85296151b82f fwd=&quot;104.219.179.22&quot; dyno= connect= service= status=503 bytes= protocol=https
  2022-05-13T21:01:43.856882+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/favicon.ico&quot; host=melon-wallet2.herokuapp.com request_id=7e0a98b6-b9d4-4c53-8906-6fc95b44fb81 fwd=&quot;104.219.179.22&quot; dyno= connect= service= status=503 bytes= protocol=https
  2022-05-13T21:01:53.011981+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/&quot; host=melon-wallet2.herokuapp.com request_id=5da051b1-0e5c-4f1b-aa68-25f50fc9d665 fwd=&quot;104.219.179.22&quot; dyno= connect= service= status=503 bytes= protocol=https
  2022-05-13T21:01:53.303822+00:00 heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/favicon.ico&quot; host=melon-wallet2.herokuapp.com request_id=9c8605cf-8194-4cec-bbad-d6dc6e9dc76e fwd=&quot;104.219.179.22&quot; dyno= connect= service= status=503 bytes= protocol=https
  </code></pre>