JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 453
  • Score
    100M100P100Q84825F
  • License MIT License - http://opensource.org/licenses/MIT

Config files that defer to env settings.

Package Exports

  • configya

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (configya) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

configya

Stupid simple configuration.

What & How

configya reads the following:

  • environment variables
  • optional configuration
  • defaults hash

Note: it is impossible to have both a configuration file and a defaults hash. Pick one.

Unless you've set a deploy-type environment variable = 'DEV', configya will always overwrite keys from a configuration file or defaults hash with duplicates found in the environment.

Key Parsing

configya parses all sources into an object hierarchy based on _ delimited key names. For example, if you have a key named RABBIT_BROKER_IP set to '127.0.0.1', and another named RABBIT_BROKER_PORT set to 5672, the resulting configuration object will be:

{
    rabbit: {
        broker: {
            ip: "127.0.0.1",
            port: "5672"
        }
    }
}

Note: All keys are lower-cased to eliminate the need for guessing games (and capslock)

Original Keys

The original keys are technically still stored on the object based on their source.

  • _env_ for original environment keys
  • _defaults_ for keys coming from a defaults hash
  • _file_ for keys coming from a file

Note: These are really here for diagnostic/backwards compatibility. You shouldn't use/rely on them in your code.

Usage

    //load configya without a config file (using only environment)
    var cfg = require('configya')();

    //load configya with a config file as well
    var cfg = require('configya')('./path/to/configuration.json');

    //load configya with a defaults hash
    var cfg = require('configya')( { RABBIT_BROKER_PORT: 5672 } );

    var port = cfg.rabbit.broker.port; // etc.

Backwards Compatibility

The original version of configya used a get method to retrieve configuration values with the ability to specify a default/fallback if the key were missing. This is technically still supported, but we think the new approach (nested keys) is nicer. Here's an example of the original API:

    var config = require( 'configya' )( './path/config.json' );

    // get the value from the config file, if an 
    // environment variable is present the environment
    // variable ALWAYS trumps the file setting unless 
    // you have deploy-type=DEV in your env settings
    config.get( 'key' );

    config.get( 'key', defaultValue );