R
Railway11mo ago
moolox

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.
No description
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...
Jump to solution
6 Replies
Percy
Percy11mo ago
Project ID: N/A
Solution
Brody
Brody11mo ago
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
moolox
mooloxOP11mo ago
poggers you! Going to give this a shot WOW - you are the freaking BOMB!! Thank you!!
Brody
Brody11mo ago
no problem!
moolox
mooloxOP11mo ago
All I had to do was change the volume path. Incredible
Brody
Brody11mo ago
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!
Want results from more Discord servers?
Add your server