Azure Functions JavaScript 本地开发环境变量

Azure Functions JavaScript Local Development Environment Variables

在 JavaScript 中开发 Azure Functions 时 locally, how would one get/set Node environment variables to use when running the functions locally with azure-functions-core-tools func host start --debug?

Documentation for Azure Functions in JavaScript 演示了通过 process.env[settingName] 定位 Function App 应用程序设置。当 published/deployed 从 azure 函数应用程序的应用程序设置中提取值时,这似乎很有效。

当尝试在命令提示符中使用 $env:FOO="bar" (powershell) 或 set FOO=bar 设置的函数中记录本地节点环境变量 (Windows) 时,它记录未定义.尝试使用命令 context.log(process.env['FOO']).

记录这些值

index.js

const foo = process.env["FOO"];

module.exports = function (context, req) {
    context.log('bar') // successfully logs 'bar' in the azure function log
    context.log(foo); // logs undefined

    if (req.query.name || (req.body && req.body.name)) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + (req.query.name || req.body.name)
        };
    } else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
    context.done();
};

感谢您提供的任何帮助!

您是否在函数应用程序的根目录中使用 local.settings.json 文件?

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