RAILWAY_REPLICA_ID empty

How can I read my variable in Railway itself? For example, I have the RAILWAY_REPLICA_ID, but it shows as empty when I use console.log." { REPLICA_ID: undefined, SERVICE_ID: undefined } console.log({ REPLICA_ID: process.env.RAILWAY_REPLICA_ID, SERVICE_ID: process.env.RAILWAY_SERVICE_ID, })
Solution:
you dont need to define it, and you shouldn't, you defining it is causing the variable to be empty
Jump to solution
26 Replies
Percy
Percy4mo ago
Project ID: 92e4a81b-58fc-4487-8c5e-6dee0616fc2f
João Dalla Villa
João Dalla VillaOP4mo ago
92e4a81b-58fc-4487-8c5e-6dee0616fc2f
Brody
Brody4mo ago
what kind of app
João Dalla Villa
João Dalla VillaOP4mo ago
Nodejs server
Brody
Brody4mo ago
can you share a minimal reproducible example? this utilities app can read the variable just fine - https://utilities.up.railway.app/env-vars?prefix=RAILWAY_REPLICA_ID
João Dalla Villa
João Dalla VillaOP4mo ago
Can I simply read the environment variables this way?
No description
No description
João Dalla Villa
João Dalla VillaOP4mo ago
Or is there another standard for reading them in the application?
Brody
Brody4mo ago
the code looks fine, but are you trying to define it as a service variable, because thats not how it works
João Dalla Villa
João Dalla VillaOP4mo ago
Hmm, I see. But is there a way to read it or to differentiate the REPLICAS within my application? 🥲
Brody
Brody4mo ago
are you trying to define it as a service variable?
João Dalla Villa
João Dalla VillaOP4mo ago
yes
Brody
Brody4mo ago
thats not how it works, dont do that, and then it will work
João Dalla Villa
João Dalla VillaOP4mo ago
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 Is there a way to differentiate my replicas at the service layer?
Brody
Brody4mo ago
the replica id is a unique id given to each replica
João Dalla Villa
João Dalla VillaOP4mo ago
Yes, that's why I would like to use this ID as a reference to distribute users among the replicas
Brody
Brody4mo ago
now that i have told you why you are having trouble with that, and how to fix it, what is blocking you now?
João Dalla Villa
João Dalla VillaOP4mo ago
Sorry, I still don't understand. How should I define it to be able to read the variable from the code?
Solution
Brody
Brody4mo ago
you dont need to define it, and you shouldn't, you defining it is causing the variable to be empty
João Dalla Villa
João Dalla VillaOP4mo ago
But I am simply trying to read it with process.env, without defining it. It was created by Railway itself, right?
Brody
Brody4mo ago
yes
João Dalla Villa
João Dalla VillaOP4mo ago
In that case, shouldn't it have a value in console.log?
Brody
Brody4mo ago
it will when you remove it from your service variables
João Dalla Villa
João Dalla VillaOP4mo ago
Hello @Brody , even though I didn't add the RAILWAY_REPLICA_ID to the service variables, I still receive it as empty in my console.log
Brody
Brody4mo ago
please provide a minimal reproducible example
João Dalla Villa
João Dalla VillaOP4mo ago
Alright, I created a simple project with NestJS and a health check endpoint. In this endpoint, I included console.log(RAILWAY_REPLICA_ID). I deployed the project on Railway with 4 replicas, but I never added RAILWAY_REPLICA_ID to the service variables. Even so, I am receiving null in console.log.
Brody
Brody4mo ago
send the repo please
Want results from more Discord servers?
Add your server