connie-lang

Configuration language for connie

Usage no npm install needed!

<script type="module">
  import connieLang from 'https://cdn.skypack.dev/connie-lang';
</script>

README

connie-lang

Configuration language for connie.

Installation

$ npm install --save connie-lang

Usage

var ConnieLang = require('connie-lang');

var config = ConnieLang.parse({
  common: {
    domain: 'mattinsler.com'
  },
  endpoints: {
    api: 'api.@{common.domain}'
  },
  server: {
    port: '${PORT:3000}'
  }
}, process.env);

Language Reference

${ENV_VAR} Environment Variable Replacement

@{ref} Self-Reference Replacement

Default Values

You can provide a default value in either of the patterns above, using : as a separator.

For instance, ${PORT:3000} means to substitute the PORT environment variable, but if that does not exist, it will return the string '3000' instead. This also works with reference patterns, like @{common.domain:foo.com}, which will use 'foo.com' as the default value if common.domain does not exist in the current config.

Examples

original config object
{
  "common": {
    "domain": "mattinsler.com"
  },
  "endpoints": {
    "api": "api.@{common.domain}"
  },
  "server": {
    "port": "${PORT:3000}"
  }
}

When this configuration is executed with an empty environment, the result is:

parsed config object
{
  "common": {
    "domain": "mattinsler.com"
  },
  "endpoints": {
    "api": "api.mattinsler.com"
  },
  "server": {
    "port": "3000"
  }
}

However, if the PORT environment variable is set to 4000, then this would change to:

parsed config object
{
  "common": {
    "domain": "mattinsler.com"
  },
  "endpoints": {
    "api": "api.mattinsler.com"
  },
  "server": {
    "port": "4000"
  }
}