Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access user-defined env vars in bluemix

Tags:

ibm-cloud

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.

like image 310
JWPerry Avatar asked Dec 02 '25 22:12

JWPerry


1 Answers

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);
like image 190
Alex da Silva Avatar answered Dec 05 '25 13:12

Alex da Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!