2 years ago
How can I read my variable in Railway itself? For example, I have the RAILWAYREPLICAID, but it shows as empty when I use console.log."
{ REPLICAID: undefined, SERVICEID: undefined }
console.log({
REPLICAID: process.env.RAILWAYREPLICAID, SERVICEID: process.env.RAILWAYSERVICEID,
})
27 Replies
2 years ago
what kind of app
2 years ago
can you share a minimal reproducible example?
this utilities app can read the variable just fine -
2 years ago
the code looks fine, but are you trying to define it as a service variable, because thats not how it works
Hmm, I see. But is there a way to read it or to differentiate the REPLICAS within my application?
2 years ago
are you trying to define it as a service variable?
2 years ago
thats not how it works, dont do that, and then it will work
To give you context, the same application has 4 replicas, but they are socket applications. I want to read my database with 1000 users and distribute 250 to each replica
2 years ago
the replica id is a unique id given to each replica
Yes, that's why I would like to use this ID as a reference to distribute users among the replicas
2 years ago
now that i have told you why you are having trouble with that, and how to fix it, what is blocking you now?
Sorry, I still don't understand. How should I define it to be able to read the variable from the code?
2 years ago
you dont need to define it, and you shouldn't, you defining it is causing the variable to be empty
But I am simply trying to read it with process.env, without defining it. It was created by Railway itself, right?
2 years ago
yes
2 years ago
it will when you remove it from your service variables
Hello @Brody , even though I didn't add the RAILWAYREPLICAID to the service variables, I still receive it as empty in my console.log
2 years ago
please provide a minimal reproducible example
Alright, I created a simple project with NestJS and a health check endpoint. In this endpoint, I included console.log(RAILWAYREPLICAID). I deployed the project on Railway with 4 replicas, but I never added RAILWAYREPLICAID to the service variables. Even so, I am receiving null in console.log.
2 years ago
send the repo please

