Reputation: 95
IBM Bluemix includes a project dashboard where environment vars may be defined. There are two sections available "VCAP_SERVICES" and "USER-DEFINED"; I know from example code that VCAP_SERVICES can be retrieved in server.js like this:
if (process.env.VCAP_SERVICES) {
var env = JSON.parse (process.env.VCAP_SERVICES);
myvar = env.foo[bar].foo;
}
I'd like to define a value in USER-DEFINED but can't figure out the syntax to retrieve it in server.js, for example this doesn't work:
var env = JSON.parse (process.env.USER-DEFINED);
which produces an error that "-DEFINED" is unknown. I've tried a few variations but can't find what works.
Upvotes: 3
Views: 2246
Reputation: 95
Solved:
var myvar= process.env.myVarName;
My guess: "VCAP_SERVICES" is a special case that Bluemix handles by segregating it in the UI from other vars, and "USER-DEFINED" is a red herring.
Upvotes: 0
Reputation: 4590
The USER-DEFINED section is actually for you to define you own environment variables. For example, I clicked in the ADD button and added a new environment variable:
Name: MY_USER_DEFINED
Value: Hello
Then I have the following Node.js code to read this variable:
var myEnv = process.env.MY_USER_DEFINED;
console.log("My user defined = " + myEnv);
Upvotes: 7