Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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!

like image 539
Alexander Staroselsky Avatar asked Dec 18 '22 04:12

Alexander Staroselsky


1 Answers

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

{
  "IsEncrypted": false,
  "Values": {
    "FOO": "-- Your Value --",
  }
}
like image 168
Cloud SME Avatar answered Jan 11 '23 23:01

Cloud SME