ibm-cloud-env module allows to abstract environment variables from various Cloud compute providers, such as, but not limited to, CloudFoundry and Kubernetes, so the application could be environment-agnostic.
The module allows to define an array of search patterns that will be executed one by one until required value is found.
npm install ibm-cloud-env
Create a JSON file containing your mappings and initialize the module
const IBMCloudEnv = ;IBMCloudEnv;
In case mappings file path is not specified in the
IBMCloudEnv.init() the module will try to load mappings from a default path of
ibm-cloud-config supports searching for values using three search pattern types - cloudfoundry, env, file.
cloudfoundryallows to search for values in VCAP_SERVICES and VCAP_APPLICATIONS environment variables
envallows to search for values in environment variables
fileallows to search for values in text/json files
credentialsobject of the matching service instance name
In your application retrieve the values using below commands
var service1credentials = IBMCloudEnv; // this will be a dictionaryvar service2username = IBMCloudEnv; // this will be a string
Following the above approach your application can be implemented in an runtime-environment agnostic way, abstracting differences in environment variable management introduced by different cloud compute providers.