set Azure Function Environment Variable for Nodejs Project
Asked Answered
M

2

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?

Mercaptopurine answered 7/8, 2019 at 6:6 Comment(0)
D
13

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

Drucilladrucy answered 29/3, 2020 at 8:44 Comment(1)
NB: for localhost development you will need to restart functions to pick up env var changes.Xylene
E
4

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

Emlynne answered 7/8, 2019 at 7:14 Comment(2)
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, thanksMercaptopurine
Thank you so much it is helpful for me @HariHaran. Please also add some tips for production-related configuration with azure function Nodejs.Mercaptopurine

© 2022 - 2024 — McMap. All rights reserved.