简体   繁体   中英

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!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM