Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read VCAP_SERVICES env variable in java script

I'm getting java script error - 'Uncaught ReferenceError: process is not defined' while trying to refer below code in my JavaScript.

if(process.env.VCAP_SERVICES){
}

Should I need to include or declare or define any thing before reading VCAP_SERVICES environment variable?

Plan is to read credentials out of it and invoke corresponding IBM Bluemix service. Can any one suggest me on priority please?

like image 565
ItsMyFist Avatar asked Jul 03 '26 20:07

ItsMyFist


1 Answers

From your comments it seems you're trying to run this as client-side javascript (through the web browser).

The VCAP_SERVICES variable is an environment variable for the host machine i.e. the server hosting your bluemix application

To access and process this variable you need to write server-side code in something like node.js, java, python etc...

It is possible to connect to a service from client-side javascript but it's very bad practice because the service credentials will have to be stored client-side. You also need to manually copy across the environment variables for your service (host, port, username, password etc..) which is also bad practice because these variables may well change over time.

like image 133
Ed Shee Avatar answered Jul 05 '26 11:07

Ed Shee



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!