I’ve created a Node droplet and when I “npm start” it (“node server.js” is executed) I get the following error:


Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)

My redis server is a droplet as well and the redis-server is running. I checked it with “systemctl status redis”. It shows “active (running)”.

I followed this tutorial to set redis up: https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04

But I get the following error when starting my backend:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using npm@6.13.7
3 info using node@v13.10.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle backend@0.1.2~prestart: backend@0.1.2
6 info lifecycle backend@0.1.2~start: backend@0.1.2
7 verbose lifecycle backend@0.1.2~start: unsafe-perm in lifecycle true
8 verbose lifecycle backend@0.1.2~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/user/backend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/us$
9 verbose lifecycle backend@0.1.2~start: CWD: /home/user/backend
10 silly lifecycle backend@0.1.2~start: Args: [ '-c', 'node server.js' ]
11 silly lifecycle backend@0.1.2~start: Returned: code: 1  signal: null
12 info lifecycle backend@0.1.2~start: Failed to exec start script
13 verbose stack Error: backend@0.1.2 start: `node server.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:316:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:316:20)
13 verbose stack     at maybeClose (internal/child_process.js:1026:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid backend@0.1.2
15 verbose cwd /home/user/backend
16 verbose Linux 4.15.0-66-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
18 verbose node v13.10.1
19 verbose npm  v6.13.7
20 error code ELIFECYCLE
21 error errno 1
22 error backend@0.1.2 start: `node server.js`
22 error Exit status 1
23 error Failed at the backend@0.1.2 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Thanks for every help!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers

Hi there @Effection,

Is your Redis server running on the same Droplet as your Node.js application or are they on two different Droplets?

If they are on two separate Droplets, note that you need to set your Redis to bind on 0.0.0.0 rather than localhost and also set your Node.js to connect to the Redis Droplet’s IP address.

If this is not the case and you are running your Redis server and Node application on the same Droplet, can you SSH to your Droplet and run the following command to make sure that Redis is listening on the correct port:

netstat -plant

Feel free to share the output here.

Hope that this helps!
Regards,
Bobby

Thanks for your fast help Bobby!

My Redis server and Node Server are on two different Droplets. I decided so due to the fact that if I shut down the Node app the Redis storage is gone (when they both run on the same Droplet). Do I assume it right?

I bind Redis now to 0.0.0.0 which I hadn’t. Then I restarted it with “sudo systemctl restart redis.service”.

In my Node app I changed the IP from 127.0.0.1 to my Droplets IP of the Redis Server (inside the .env-file). But it still gives me the “Redis connection to 127.0.0.1:6379” error which is very confusing.

EDIT: here is the netstat -plant output

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      -
tcp        0    816 *DROPLET-IP*:22       *77........*     ESTABLISHED -
tcp6       0      0 :::22                   :::*                    LISTEN      -

I realized that somewhere in my backend code there must be a default value set for the Redis URI and port …

Submit an Answer