简体   繁体   English

为 Nodejs 项目设置 Azure 函数环境变量

[英]set Azure Function Environment Variable for Nodejs Project

How to set Azure Function Environment Variable for development and production-ready code?如何为开发和生产就绪代码设置 Azure 函数环境变量?

ExpressJS already provided Environment config file, how to set Azure Function Environment Variable? ExpressJS 已经提供了环境配置文件,如何设置 Azure 函数环境变量?

For development you can add variables in local.settings.json :对于开发,您可以在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这将覆盖local.settings.json 中的变量

Azure Functions provide us with a local.settings.json file where we can define these variables. Azure Functions 为我们提供了一个local.settings.json文件,我们可以在其中定义这些变量。

{
  "IsEncrypted": false,
  "Values": {
    "FOO": "-- Your Value --",
  }
}

You can access it from your code using process.env["FOO"]您可以使用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.如果您希望在部署后进行设置,则在发布功能时,请在发布期间使用--publish-local-settings -i开关。

Docs for publish 发布文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM