简体   繁体   中英

Node.js - how to read Environmental variables from Cloud Foundry application?

I am working on the Node.js project and need to login to Cloud Foundry and read environmental variables (basically, credentials) of one application. So far, I was able to login and target the correct organization with the help of '@sap/cf-tools' package. Now, the last step remains, the equivalent of command

cf env APP_NAME

The problem is that '@sap/cf-tools' doesnt support yet this functionality and I haven't found any other which would do it. Did someone else face this problem and if yes, how did you solve it? Is there some npm package I have overlooked? Or I will be forced to run "cf env" with "-v" parameter and try to get to the desired EnvVariables through the series of axios calls? Thank you.

There's no need to use a series of Axios calls. Take a look at the following package https://www.npmjs.com/package/@sap/xsenv . It should fit your use case.

var xsenv = require('@sap/xsenv');
var services = xsenv.readServices();
var svc = services[process.env.SERVICE_NAME];

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