R
Railway9mo 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
Percy9mo ago
Project ID: N/A
Solution
Brody
Brody9mo 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
moolox9mo ago
poggers you! Going to give this a shot WOW - you are the freaking BOMB!! Thank you!!
Brody
Brody9mo ago
no problem!
moolox
moolox9mo ago
All I had to do was change the volume path. Incredible
Brody
Brody9mo 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