open .env: no such file or directory

AnonymousTRIAL

9 months ago

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

0 Replies

AnonymousTRIAL

9 months ago

29b3df72-b848-4094-8524-2e9fd0efe9bf


9 months 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)


9 months ago

You would want to set the variables in the VARIABLES tab of the service


AnonymousTRIAL

9 months 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


9 months ago

don't log.Fatal() on the error returned by godotenv


AnonymousTRIAL

9 months ago

Oh yeah that I did


AnonymousTRIAL

9 months ago

Will fix. Thnx


9 months 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


AnonymousTRIAL

9 months ago

Thanks for the advice, pretty new to GO and just creating my first api. 🙏


9 months ago

awesome, love to hear that!


AnonymousTRIAL

9 months ago

And my deployment is successful. Thanks again folks


9 months ago

no problem


open .env: no such file or directory - Railway Help Station