node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »


IBM Cloud Environment

Bluemix powered Travis Coveralls Codacy Version DownloadsMonthly DownloadsTotal License Conventional Commits

The 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 = require('ibm-cloud-env');

In case mappings file path is not specified in the IBMCloudEnv.init() the module will try to load mappings from a default path of /server/config/mappings.json.

Supported search patterns types

ibm-cloud-config supports searching for values using three search pattern types - cloudfoundry, env, file.

  • Using cloudfoundry allows to search for values in VCAP_SERVICES and VCAP_APPLICATIONS environment variables
  • Using env allows to search for values in environment variables
  • Using file allows to search for values in text/json files

Example search patterns

  • cloudfoundry:service-instance-name - searches through parsed VCAP_SERVICES environment variable and returns the credentials object of the matching service instance name
  • cloudfoundry:$.JSONPath - searches through parsed VCAP_SERVICES and VCAP_APPLICATION environment variables and returns the value that corresponds to JSONPath
  • env:env-var-name - returns environment variable named "env-var-name"
  • env:env-var-name:$.JSONPath - attempts to parse the environment variable "env-var-name" and return a value that corresponds to JSONPath
  • file:/server/config.text - returns content of /server/config.text file
  • file:/server/config.json:$.JSONPath - reads the content of /server/config.json file, tries to parse it, returns the value that corresponds to JSONPath

mappings.json file example

    "service1-credentials": {
        "searchPatterns": [
    "service2-username": {

Using the values in application

In your application retrieve the values using below commands

var service1credentials = IBMCloudEnv.getDictionary("service1-credentials"); // this will be a dictionary
var service2username = IBMCloudEnv.getString("service2-username"); // 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.