Azure Functions JavaScript 本地开发环境变量 [英] Azure Functions JavaScript Local Development Environment Variables
问题描述
在 JavaScript 本地开发 Azure Functions 时本地,使用 azure-functions-core-tools func host start --debug
?
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 Functions 演示通过 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)code> 在命令提示符下,它记录未定义.尝试使用命令
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 Functions JavaScript 本地开发环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!