How to set Azure Function Environment Variable for development and production-ready code?
ExpressJS already provided Environment config file, how to set Azure Function Environment Variable?
You can signal Node. js that you are running in production by setting the NODE_ENV=production environment variable. in the shell, but it's better to put it in your shell configuration file (e.g. . bash_profile with the Bash shell) because otherwise the setting does not persist in case of a system restart.
You really do not need to set up your own environment to start learning Node. js. Reason is very simple, we already have set up Node.
For development you can add variables in local.settings.json :
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"host": "localhost",
}
}
And use it with :
process.env["host"]
For production you can add a Configuration of the Application in :
And this will override the variables in local.settings.json
Azure Functions provide us with a local.settings.json
file where we can define these variables.
{
"IsEncrypted": false,
"Values": {
"FOO": "-- Your Value --",
}
}
You can access it from your code using process.env["FOO"]
Refer official docs
If you want the settings post deployment, when you publish the function use the --publish-local-settings -i
switch during publishing.
Docs for publish
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With