Golang .env keys not reading


(upload://9OBqL47hLrXAXS8K1fTKMb3lJDh.png)

golang web server not reading .env. it works locally not when I deploy.

func envMongoURI() string {
err := godotenv.Load()
if err != nil {
log.Fatal(“Error loading .env file”)
}

return os.Getenv("MONGO")

}

func GetPort() string {
err := godotenv.Load()
if err != nil {
log.Fatal(“Error loading .env file”)
}

return os.Getenv("PORT")

}

Your repository probably doesn’t contain a .env file, which is a good thing (never commit secrets to a repository). You should only have and use .env locally, then Dashboard defined Environment Variables on Render. Environment Variables and Secrets | Render Docs

Sorry, I am a bit confused. If I do use .env on rendered then what would I use? I have defined Environment Variables on the dashboard but what should I call instead of .env

You shouldn’t call anything. Environment Variables are automatically available to your application at run time, you only have to reference them. It’s only in Development / locally where you have to explicitly load .env in order for them to become available in the environment.

“Thank you for your help.”

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.