Azure App Service (Windows) Config Variable

Brass Contributor

I'm having an issue reading env variables on Azure App Service Windows instance. I use dotenv nodejs package for storing my env variables in .env file. It works perfectly fine on my local machine (Windows 10), but the same does not when hosted on a Windows App service. I tried some troubleshooting by printing out the env variables at run time and I get blank output for the same. Somehow it's not able to read the variables in the .env file.

 

I also ensured that the .env file and the entries are intact on the deployed host by logging onto the console in the portal.

 

What am I doing wrong?

4 Replies

@eynarain Did you try setting the environment variables using the Configuration settings for your webapp?

Check out this screenshot, I guess this should help you setting your environment variables.

Screenshot_145.png

You may find more info on this at: https://docs.microsoft.com/en-us/azure/app-service/configure-common
I hope this solves your problem.

 

Thanks

@akhilvattsThat did the trick. Thanks for letting me know of this.

Hi @akhilvatts how do you suggest to work with Application Settings on local dev environments?  Using .evn.local, .env.qa and .env.prd allows me to have specific environment variables managed through my codebase.  I use the pipeline to convert .env.<environment> to .env and then inject sensitive values against keys such as password from a vault.

 

Managing environment variables through Application Settings means more overhead whenever I need to introduce new variables, especially non-sensitive ones.

It seems like this was a specific problem with my Python Flask application.  Since Azure App Service uses gunicorn to start Python applications and not the Flask CLI, the .env file was not getting loaded into the project because the Flask CLI will typically load the python-dotenv package.  Once I loaded it myself into main.py, it started working again.