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^^
Solution:
railway injects the service variables as environment variables, this has nothing to do with whether or not you have a .env file
Jump to solution
13 Replies
Percy
Percy•2y ago
Project ID: N/A
Solution
Brody
Brody•2y ago
railway injects the service variables as environment variables, this has nothing to do with whether or not you have a .env file
nicolas06875
nicolas06875OP•2y ago
Ok so, that give me the possibility to work in local, push and don't worry about to change anything
Brody
Brody•2y ago
yes
nicolas06875
nicolas06875OP•2y ago
Nice thanks for your speed reply
Brody
Brody•2y ago
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
nicolas06875
nicolas06875OP•2y ago
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
Brody
Brody•2y ago
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?
nicolas06875
nicolas06875OP•2y ago
this ?
Brody
Brody•2y ago
where is your database hosted
nicolas06875
nicolas06875OP•2y ago
on an apartment host
Brody
Brody•2y ago
i dont know what that means, but carry on
nicolas06875
nicolas06875OP•2y ago
Thanks 🙂
Want results from more Discord servers?
Add your server