Is there way to run commands/scripts remotely?

If I want to run scripts for example to manage my database, is that possible? Like heroku run
Solution:
railway run runs the command locally with the environment variables of the service
Jump to solution
28 Replies
Percy
Percy12mo ago
Project ID: N/A
Joe Lanman
Joe LanmanOP12mo ago
N/A semi answering my own question, I guess if I use railway run the DATABASE_URL will point at the remote DB and therefore run remotely. But it would be good to know if it is possible to run arbitrary commands remotely
Solution
Adam
Adam12mo ago
railway run runs the command locally with the environment variables of the service
Adam
Adam12mo ago
it does not run the command in the service container Railway does not support ssh
Joe Lanman
Joe LanmanOP12mo ago
thanks, but what I said is correct no? just to check
Adam
Adam12mo ago
No, the command will not run remotely. The environment variables will be copied from the remote though
Joe Lanman
Joe LanmanOP12mo ago
I know it runs locally, but the DATABASE_URL should connect remotely and run there
Adam
Adam12mo ago
If you're querying a database using the DATABASE_URL then yes, that query will be run on the database
Joe Lanman
Joe LanmanOP12mo ago
thanks!
Joe Lanman
Joe LanmanOP12mo ago
hmm actually I don't think that will work. I have a .env file and call dontenv.config() so I think it will just use my local environment vars yeh I checked and it doesnt work
Brody
Brody12mo ago
don't call dotenv.config locally?
Joe Lanman
Joe LanmanOP12mo ago
you mean dont call it when using railway run? what would be a robust check for that?
Brody
Brody12mo ago
check the NODE_ENV (I that's what it's called) variable
Joe Lanman
Joe LanmanOP12mo ago
ha was just typing that, cool thanks
Brody
Brody12mo ago
on railway it's automatically set to production locally, it probably wouldn't be set or definitely wouldn't be set to production
Joe Lanman
Joe LanmanOP12mo ago
if (process.env.NODE_ENV != "production") dotenv.config()
Brody
Brody12mo ago
looks about right
Joe Lanman
Joe LanmanOP12mo ago
thanks again!
Brody
Brody12mo ago
no problem!
Joe Lanman
Joe LanmanOP12mo ago
just in case its helpful to others, I think I was wrong - dotenv does NOT overwrite exising env vars.. so I'm really not sure why it wasn't working. But it is now, apologies for any confusion! also, NODE_ENV is not set by default on Railway, you have to set it manually
Brody
Brody12mo ago
last I checked it is set by nixpacks, but it would not be visible in the service variables
Joe Lanman
Joe LanmanOP12mo ago
hm, I just tried a console.log(process.env.NODE_ENV) on railway and it was blank well, undefined
Brody
Brody12mo ago
building with nixpacks?
Joe Lanman
Joe LanmanOP12mo ago
I don't know, how to check?
Brody
Brody12mo ago
then it's nixpacks
Joe Lanman
Joe LanmanOP12mo ago
are these other env vars documented somewhere?
Joe Lanman
Joe LanmanOP12mo ago
thanks!
Want results from more Discord servers?
Add your server