Connecting to Private Services Node API <> Redis
My node js sever is having troubling finding the redis/redis-stack-server image in the network. I'm using the traditional 6379 port and the redis-stack-server.railway.internal host name but my node DNS keeps throwing
[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis-stack-server.railway.internal
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
When I spin up my node server. This works fine on local and together in a docker compose file with the same redis image locally. What am I doing wrong to connect to the redis-stack-server?Solution:Jump to solution
I went with this set-up and its all working:
Dockerfile
```# Start with a node base image
FROM node:21...
36 Replies
Project ID:
N/A
are you using ioredis?
yes
show me the connection object please
const options = {
host: REDIS_HOST,
port: REDIS_PORT,
retryStrategy: (times) => {
return Math.min(times * 50, 2000);
},
};
const pubsub = new RedisPubSub({
publisher: new Redis(options),
subscriber: new Redis(options),
});
PORT: 6379, HOST: redis-stack-server.railway.internaltriple backticks btw
ty
you're missing username, password, and, family: 0
If I have the UN and PW then the address will resolve?
At the moment it seems like it can't pick up the internal addy
if you have family: 0 the address should resolve, you'd need the username and password regardless
interesting, may I ask why 'family' is required?
So ...
?
the internal network is ipv6 only, ioredis assumes ipv4 by default, family: 0 tells ioredis to use both ipv6 and ipv4
yeah looks good
I knew it had something to do with the IPv6
thanks I'll get back to hacking 🚀
no problem, let me know if it works
though this is how i would do it
in the variables for your app, reference the redis database's private url like this
then connect to redis like this
Hmm.. here's the stack trace. Still throwing the ENOTFOUND with the private address
you may need to add a 3 second sleep to your start script
whats your current start script
is that what you're looking for?
nope, im looking for your start script, it would be in your package.json
oh yeah duh
one second
"prod": "NODE_ENV=production node app.js",
how have you told railway to run that script?
It runs from a Dockerfile I have in the project
do you use this Dockerfile locally too?
yes
okay then in your service settings, set the start command to
sleep 3 && npm run prod
and just a quick question, why Dockerfile instead of nixpacks?I didn't really know what nixpacks was until I started working on Railway last week
fair enough
mind if i make a suggestion on your dockerfile?
Sure thing. I'm relatively new to coding ~2 years.
nothing major
neat, I'll have a look at the ci command
thanks very much.
One question, when you mention my project's service settings what are you referring to
im referring to the service's settings 😅
I see, my fault. I thought you were referring to something related to the node app
no worries
Wanted to follow up and thank you for all the help. The "sleep 3 &&.." custom start command completes the build just fine but I see no deployment logs. The service reports completed but that doesn't seem normal.
completed means it exited without an error code
try setting the start command to
Solution
I went with this set-up and its all working:
Dockerfile
Start scripts
thats a very good way of doing it