Gopal Meena
Gopal Meena

Reputation: 109

set Azure Function Environment Variable for Nodejs Project

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?

Upvotes: 9

Views: 9376

Answers (2)

Álvaro Agüero
Álvaro Agüero

Reputation: 4800

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

Upvotes: 13

HariHaran
HariHaran

Reputation: 4099

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

Upvotes: 4

Related Questions