Azure Functions JavaScript Local Development Environment Variables

365
August 26, 2017, at 06:56 AM

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!

Answer 1

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

{
  "IsEncrypted": false,
  "Values": {
    "FOO": "-- Your Value --",
  }
}
READ ALSO
Why is my download link requiring control click to download?

Why is my download link requiring control click to download?

I am running a pretty basic nodejs server to host a site, and all of a sudden this week one of my download links started to just redirect to the index

216
Node.Js - Generate canvas DOM objects and pass to EJS / template engine

Node.Js - Generate canvas DOM objects and pass to EJS / template engine

I get to ask stupid questions today as I'm leaning Nodejs

281
Docker compose, reactJS app build to dist, how to pass to 1st nginx

Docker compose, reactJS app build to dist, how to pass to 1st nginx

Im struggling with node reactJS app and dockerI use docker-compose, there are plenty microservices, dbs etc

248
unable to create simple websocket - NodeJS

unable to create simple websocket - NodeJS

I am trying to follow this tutorial: https://wwwsimonewebdesign

367