RAILWAY_REPLICA_ID empty
vinicoder
PROOP

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

vinicoder
PROOP

2 years ago

92e4a81b-58fc-4487-8c5e-6dee0616fc2f


2 years ago

what kind of app


vinicoder
PROOP

2 years ago

Nodejs server


2 years ago

can you share a minimal reproducible example?
this utilities app can read the variable just fine -


vinicoder
PROOP

2 years ago

Can I simply read the environment variables this way?

1265835416578429000
1265835416825626600


vinicoder
PROOP

2 years ago

Or is there another standard for reading them in the application?


2 years ago

the code looks fine, but are you trying to define it as a service variable, because thats not how it works


vinicoder
PROOP

2 years ago

Hmm, I see. But is there a way to read it or to differentiate the REPLICAS within my application?


vinicoder
PROOP

2 years ago

🥲


2 years ago

are you trying to define it as a service variable?


vinicoder
PROOP

2 years ago

yes


2 years ago

thats not how it works, dont do that, and then it will work


vinicoder
PROOP

2 years 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


vinicoder
PROOP

2 years ago

Is there a way to differentiate my replicas at the service layer?


2 years ago

the replica id is a unique id given to each replica


vinicoder
PROOP

2 years ago

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?


vinicoder
PROOP

2 years ago

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


vinicoder
PROOP

2 years ago

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


vinicoder
PROOP

2 years ago

In that case, shouldn't it have a value in console.log?


2 years ago

it will when you remove it from your service variables


vinicoder
PROOP

2 years ago

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


vinicoder
PROOP

2 years ago

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


Loading...