Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 996
Gopal Meena Avatar asked Aug 07 '19 06:08

Gopal Meena


People also ask

How do you set environment as production in node JS?

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.

Do we need to set environment variables for node JS?

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.


2 Answers

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

like image 117
Álvaro Agüero Avatar answered Oct 17 '22 02:10

Álvaro Agüero


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

like image 3
HariHaran Avatar answered Oct 17 '22 03:10

HariHaran