简体   繁体   中英

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?

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 ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM