[英]Azure Functions JavaScript Local Development Environment Variables
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函数时,如何使用azure-functions-core-tools
func host start --debug
在本地运行函数时获取/设置Node环境变量?
Documentation for Azure Functions in JavaScript demonstrate targeting Function App application settings via process.env[settingName]
. JavaScript中的Azure功能文档演示了通过
process.env[settingName]
定位功能应用程序应用程序设置。 This seems to work great when published/deployed pulling the values from application settings of the azure function app. 当发布/部署从azure功能应用程序的应用程序设置中提取值时,这似乎很有效。
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. 尝试在使用
$env:FOO="bar"
(powershell) set FOO=bar
的函数中记录本地节点环境变量(Windows)或在命令提示符中set FOO=bar
时,它会记录未定义。 Attempting to log these values using command context.log(process.env['FOO'])
. 尝试使用命令
context.log(process.env['FOO'])
记录这些值。
index.js 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! 感谢您提供任何帮助!
Are you using local.settings.json
file in the root of your function app? 您是否在功能应用程序的根目录中使用
local.settings.json
文件?
{
"IsEncrypted": false,
"Values": {
"FOO": "-- Your Value --",
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.