Shared Variables Not Injected Into Service Environment on Railway

n1ckgriffin
TRIAL

8 months ago

Hi everyone,

I’m currently deploying a backend service on Railway, and I’m running into an issue where my Shared Variables are not being injected into the process.env of my service.

Here’s what I’ve done so far:

  1. I added the necessary variables (e.g., GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, MONGODB_URI, etc.) under Project Settings > Shared Variables.

  2. I confirmed that the variable names are correct and match what I’m accessing in my code (e.g., process.env.GOOGLE_CLIENT_ID).

  3. I redeployed the service using railway up after adding the variables.

  4. However, when I log process.env in my server.js, none of these variables show up. Instead, GOOGLE_CLIENT_ID and others appear as undefined.

Am I missing something in how shared variables are supposed to work? I have this working locally, and it's kinda confusing because I have some variables not being injected such as GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, MONGODB_URI, and FRONTEND_URL, while I have others such as NODE_ENV and PORT being injected. Any guidance or suggestions would be greatly appreciated!

Thanks in advance!

Solved

1 Replies

You need to reference the shared varaible within the service settings or else it won't get exposed to the deployment.

It seems that you are now using manual references but in the future- you can use the variable template syntax to reference the Railway defined values like so ${{GOOGLE_CLIENT_ID}}

Hopefully that clears things up. (And sorry...)


Status changed to Awaiting User Response Railway 8 months ago


Railway
BOT

a month ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway about 2 months ago


Shared Variables Not Injected Into Service Environment on Railway - Railway Help Station