Abdelellah Dandashi
Abdelellah Dandashi

Reputation: 107

can i set node environment variable in Object format in Azure

In my nodejs project during development I'm using .env file for using environment variables

and one of the variables is set to be like this

varName = {"key1": "value2", "key2":"value2"}

can i set the same variable with same format in azure environment variable ?? does azure accept it ?

please note: that i have no access to azure and i am only allowed to work locally on my machine where my code is working fine

Upvotes: 0

Views: 357

Answers (1)

Peter Pan
Peter Pan

Reputation: 24138

Sure, you can set the same variable with same format in azure environment variable, as the figure below. I added a new application setting in the tab Configuration of Azure WebApp on Azure portal.

enter image description here

Then, I moved to the Kudu console of the Azure WebApp to inspect whether the TEST variable with a json string exists via the code node -e "console.log(process.env)" as the figure below.

enter image description here

And I found it as the figure below.

enter image description here

As @AZ_ said, the TEST variable value is a string, you need to use JSON.parse to convert it to JSON object.

var test = JSON.parse(process.env.TEST);
console.log(test.key1);

enter image description here

Upvotes: 1

Related Questions