Small question about how environnement variables works
Hey, today i deployed my API (Node, MySQL) for the first time on Railway. All works fine but i'm wondering something and I have no response.
When I work in local, I got a .env file with for exemple, the variables I need to be connected to my DB (MySQL/XAMPP) and I work with localhost... url. But on Railway i must set variables that my database host give me.
My question is : how Railway, when read these line for exemple ''const { DB_SERVEUR, DB_DATABASE, DB_USERNAME, DB_PASSWORD } = process.env;
const dataBase = new Sequelize(DB_DATABASE, DB_USERNAME, DB_PASSWORD, {
host: DB_SERVEUR,
dialect: 'mysql',
})'' know that it must read his variables and not my personnal .env ? I think this is beceause my .env is in the gitignore but how he know that he must replace the .env variables by the variables I give him ? If someone know how all of this work, and can explain me, thanks a lot ! Sorry for bad english^^
})'' know that it must read his variables and not my personnal .env ? I think this is beceause my .env is in the gitignore but how he know that he must replace the .env variables by the variables I give him ? If someone know how all of this work, and can explain me, thanks a lot ! Sorry for bad english^^
Solution:Jump to solution
railway injects the service variables as environment variables, this has nothing to do with whether or not you have a .env file
13 Replies
Project ID:
N/A
Solution
railway injects the service variables as environment variables, this has nothing to do with whether or not you have a .env file
Ok so, that give me the possibility to work in local, push and don't worry about to change anything
yes
Nice thanks for your speed reply
but i will say, if you did push a .env file, your .env loader that you run in code will replace railways environment variables of the same name
When it read the line I shared above, it just take the variables I provide on Railway ? So DB_SERVEUR = DB_SERVEUR from the website etc
correct, unless you had a .env file with variables of the same name.
railway variable: HELLO=WORLD
.env variable: HELLO=SKY
in this scenario, the variable in the .env file will replace the railway variable, but you have the .env file in your .gitignore so nothing from the (non existent) .env file can replace the railway variables
but id just like to check something, can you show me the a screenshot of your railway service variables please?
this ?
where is your database hosted
on an apartment host
i dont know what that means, but carry on
Thanks 🙂