9

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?

Hardik Shah
  • 4,042
  • 2
  • 20
  • 41
Gopal Meena
  • 99
  • 1
  • 7

2 Answers2

11

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 :

enter image description here

enter image description here

And this will override the variables in local.settings.json

Álvaro Agüero
  • 4,494
  • 1
  • 42
  • 39
3

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

HariHaran
  • 3,642
  • 2
  • 16
  • 33
  • Thanks for the response. Locally is working fine, but I want to set the same local.settings.json file setup when I deploy my azure function. is any way please guide me, thanks – Gopal Meena Aug 07 '19 at 07:35
  • 1
    Thank you so much it is helpful for me @HariHaran. Please also add some tips for production-related configuration with azure function Nodejs. – Gopal Meena Aug 07 '19 at 09:31