10 months ago
I have been trying to figure out some basic connections to use "railway run" locally for development, and have struggled where the documentation appears to be out of date or too thin (or where I'm being dumb).
I have a NodeJS express service and a Postgres service. I've (finally) gotten the express service able to connect to Postgres when deployed, but "railway run npm start" locally gives me an ENOTFOUND error accessing meticulous-empthy.railway.internal. (Which is obtained via me defining a DATABASEURL= ${{ meticulous-empathy.DATABASEURL }} for the express service)
running railway link -p PROJECTID still asks for which service to connect to (docs don't read like that should happen?) and I'm currently connected to the express service. Is there a step I've missed to make this work locally?
Project ID:
e1777fb1-9108-4e98-8bbd-60602862aa10
0 Replies
From skimming other answers, this appears to be working as intended (local deploys will have to connect using public addresses), but I'm unclear how to have my code use variables but have different values for those variables when running using "railway run"
10 months ago
railway link
will ask you what service you want to connect to for running future commands like railway up
But to accomplish what you are trying to do, try running railway shell
after linking to your express service. Then you should be able to run npm start
railway shell
will start a new shell session with your selected services environment variables injected into it
Running railway shell
tells me I'm in a subshell, and npm start
starts my express server locally, but it dies with the exact same ENOTFOUND message trying to connect to the Postgres service.
And still says the internal address (I'm unclear if that's the expected value)
10 months ago
Yes, it will launch a sub shell, but you are not on the internal network, so, you would need to reference your public url for database connection locally
Do I need to add conditional code to check for that? I thought the idea of the variables is that they'd reflect the necessary values.
10 months ago
If the service is not live on railway, you will not be on the internal network, so, you cannot connect to an internal domain
Yes, you said that. My question was how. I don't see how railway shell is useful then. The guides I found for plugins (pre service, I guess?) such as your own blog post suggested I could connect to Postgres without having to write new conditional code.