Azure函数JavaScript本地开发环境变量 [英] Azure Functions JavaScript Local Development Environment Variables

查看:77
本文介绍了Azure函数JavaScript本地开发环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaScript中开发Azure函数时在本地,使用

When developing Azure Functions in JavaScript 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?

文档 JavaScript中Azure函数的功能演示了如何通过process.env[settingName]定位到Function App应用程序设置.当发布/部署从azure函数应用程序的应用程序设置中提取值时,这似乎非常有用.

Documentation for Azure Functions in JavaScript demonstrate targeting Function App application settings via process.env[settingName]. This seems to work great when published/deployed pulling the values from application settings of the azure function app.

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

When trying to log local node environment variables (Windows) within the function that were set using either $env:FOO="bar" (powershell) or set FOO=bar in the command prompt, it logs undefined. Attempting to log these values using command 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();
};

感谢您提供的任何帮助!

Thank you for any help you can provide!

推荐答案

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

Are you using local.settings.json file in the root of your function app?

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

这篇关于Azure函数JavaScript本地开发环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆