Can you dynamically check if you're in Railway vs local environment without .env files?
Project is Node.JS, Express, and SQLite. Is there a way to write an if statement to somehow check if the app is in railway?
I have to add a "." before my SQLite database path in local development for the app to launch (using relative path). Example:
let db = new sqlite3.Database('./database/database.db');
But on railway volumes, it does not seem to accept relative path. I have to take the period out. Example:
let db = new sqlite3.Database('/database/database.db');
Is there a way to add an if statement to somehow check if the app is in railway? Trying to avoid having to take the period out every single time I deploy to railway. I know it's a small change but it's annoying with version control.
Solution:Jump to solution
yeah just check for something like the existence of the
RAILWAY_ENVIRONMENT_NAME
variable https://docs.railway.app/reference/variables#railway-provided-variables
but instead, leave the period, and mount the volume to /app/database/
instead, since your project is placed inside of a /app
folder.
so the relative path of ./database/database.db
will resolve to /app/database/database.db
when on railway, and if you mount your volume to /app/database/
then your database.db
file gets saved to the volume...6 Replies
Project ID:
N/A
Solution
yeah just check for something like the existence of the
RAILWAY_ENVIRONMENT_NAME
variable https://docs.railway.app/reference/variables#railway-provided-variables
but instead, leave the period, and mount the volume to /app/database/
instead, since your project is placed inside of a /app
folder.
so the relative path of ./database/database.db
will resolve to /app/database/database.db
when on railway, and if you mount your volume to /app/database/
then your database.db
file gets saved to the volume you! Going to give this a shot
WOW - you are the freaking BOMB!! Thank you!!
no problem!
All I had to do was change the volume path. Incredible
yep easy enough
just wanna also thank you, you asked a question, but you also said the complete reasoning behind asking the question, therefore I was able to help with the actual problem!