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
?
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.
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!
Are you using local.settings.json
file in the root of your function app?
{
"IsEncrypted": false,
"Values": {
"FOO": "-- Your Value --",
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With