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:Jump to solution
railway run
runs the command locally with the environment variables of the service28 Replies
Project ID:
N/A
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 remotelySolution
railway run
runs the command locally with the environment variables of the serviceit does not run the command in the service container
Railway does not support ssh
thanks, but what I said is correct no?
just to check
No, the command will not run remotely. The environment variables will be copied from the remote though
I know it runs locally, but the DATABASE_URL should connect remotely and run there
If you're querying a database using the DATABASE_URL then yes, that query will be run on the database
thanks!
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 workdon't call dotenv.config locally?
you mean dont call it when using railway run?
what would be a robust check for that?
check the NODE_ENV (I that's what it's called) variable
ha was just typing that, cool thanks
on railway it's automatically set to production
locally, it probably wouldn't be set or definitely wouldn't be set to production
if (process.env.NODE_ENV != "production") dotenv.config()
looks about right
thanks again!
no problem!
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
last I checked it is set by nixpacks, but it would not be visible in the service variables
hm, I just tried a console.log(process.env.NODE_ENV) on railway and it was blank
well,
undefined
building with nixpacks?
I don't know, how to check?
then it's nixpacks
are these other env vars documented somewhere?
thanks!