a month ago
So when I use godotenv.Load() in my production code, all the env variables will not be found even though I have set the variable in Railway and deploy it. However it works when I remove the godotenv.Load().
The problem is:
I need to use godotenv.Load() in development, how can i resolve this?
10 Replies
a month ago
bump
a month ago
It looks like (according to google)
godotenv.Load() overwrites existing env vars possibly replacing the ones injected by railway. If you were to remove that from your code for testing purposes would it work?
a month ago
If I remove it from the code, the deployment works. However, the problem it there are too much hassle with it since it is needed in development stage, and I have to remove it in deployments.
a month ago
bum
monnss69
If I remove it from the code, the deployment works. However, the problem it there are too much hassle with it since it is needed in development stage, and I have to remove it in deployments.
a month ago
Can you explain a bit more about this? I'm not quite sure I follow.
Your .env injects env variables into runtime in dev.
In production railway does this so you can read them just fine.
a month ago
deleted
error
Can you explain a bit more about this? I'm not quite sure I follow. Your .env injects env variables into runtime in dev. In production railway does this so you can read them just fine.
a month ago
Yes, as usual you don't push your .env on production code right.
So, now when I deploy my production code, I suspect the godotenv.Load() will not find my .env and overwrites all my variables that I set on Railway and therefore the deployments on Railway can't find my environment variable.
That's why atm, before pushing code to production I have to remove all the godotenv.Load() statement used in my development code.
monnss69
Yes, as usual you don't push your .env on production code right.So, now when I deploy my production code, I suspect the godotenv.Load() will not find my .env and overwrites all my variables that I set on Railway and therefore the deployments on Railway can't find my environment variable.That's why atm, before pushing code to production I have to remove all the godotenv.Load() statement used in my development code.
a month ago
If you can detect whether you are in production with an env flag you can conditionally do godotenv.Load().
In prod use the variables section.
What I do is on start have something that exports all the env vars I need into a config file (config.rs or config.go) and that config.go will cause a crash if it cant find all the variables it needs ensuring everything is started and you wont crash from no variables at runtime
error
If you can detect whether you are in production with an env flag you can conditionally do godotenv.Load().In prod use the variables section. What I do is on start have something that exports all the env vars I need into a config file (config.rs or config.go) and that config.go will cause a crash if it cant find all the variables it needs ensuring everything is started and you wont crash from no variables at runtime
a month ago
That sounds good, I will try it.
monnss69
That sounds good, I will try it.
a month ago
Sounds good! Happy I could help
Status changed to Solved brody • 28 days ago