R
Railway5mo ago
irwnd2

open .env: no such file or directory

Hi i'm trying to deploy my Go rest api. but kept getting this error open .env: no such file or directory after creating the image. Is it related to the .env file or what. Thanks
No description
Solution:
the ideal fix would be to first check if the .env file exists, and if so, then load from it, and as long as the file does exist you are safe to log.Fatal on the error returned
Jump to solution
11 Replies
Percy
Percy5mo ago
Project ID: 29b3df72-b848-4094-8524-2e9fd0efe9bf
irwnd2
irwnd2OP5mo ago
29b3df72-b848-4094-8524-2e9fd0efe9bf
MantisInABox
MantisInABox5mo ago
You should not be including or using .env files in your production ready project, you should be using os.Getenv("ENVIRONMENT_VARIABLE") where possible. But the error you are seeing is most likely caused by your .env file not being included in your repo (which you should never do) You would want to set the variables in the VARIABLES tab of the service
irwnd2
irwnd2OP5mo ago
Yes that I'm being aware too. I did set the variable through VARIABLES in setting. Here wait I'll take the screen shot
Brody
Brody5mo ago
don't log.Fatal() on the error returned by godotenv
irwnd2
irwnd2OP5mo ago
Oh yeah that I did Will fix. Thnx
Solution
Brody
Brody5mo ago
the ideal fix would be to first check if the .env file exists, and if so, then load from it, and as long as the file does exist you are safe to log.Fatal on the error returned
irwnd2
irwnd2OP5mo ago
Thanks for the advice, pretty new to GO and just creating my first api. 🙏
Brody
Brody5mo ago
awesome, love to hear that!
irwnd2
irwnd2OP5mo ago
And my deployment is successful. Thanks again folks
Brody
Brody5mo ago
no problem
Want results from more Discord servers?
Add your server