config-load

0.1.1 • Public • Published

config-load.js

Load config from a tree of JS/JSON files

Current status

NPM version Build Status Dependency Status Dev dependency Status Coverage Status

Usage

Installation

npm install config-load

Loading

var configLoad = require('config-load');

configLoad([path] [, options])

Loads all JS/JSON config files under path, recursively gathering them from the tree structure.

Uses require-folder-tree - see docs for that for explanation of how files are loaded.

If path is not provided, defaults to process.cwd() + '/config'.

Options

env

Environment type - creates a selector (see below).

Defaults to process.env.NODE_ENV || 'development'

selectors

Object determining what parts of the config object to switch dependent on selectors provided.

Defaults to { env: options.env }

Example

If config file parsing produces:

{
    db: {
        server: 'localhost',
        database: 'myDB'
    },
    env: {
        development: {
            db: {
                password: 'dev db password'
            }
        },
        production: {
            db: {
                password: 'production db password'
            }
        }
    },
    otherSetting: 'foo'
}

Then calling:

configLoad(path, { selectors: { env: 'development' } } )

returns:

{
    db: {
        server: 'localhost',
        database: 'myDB',
        password: 'dev db password'
    },
    otherSetting: 'foo'
}
null value

If a selector's value is null, it takes the name key only.

If config file parsing produces:

{
    url: 'http://example.com/',
    local: {
        url: 'http://mysite.com/'
    }
}
configLoad(path, { selectors: { local: null } } )

returns:

{
    url: 'http://mysite.com/'
}

Tests

Use npm test to run the tests. Use npm run cover to check coverage.

Changelog

See changelog.md

Issues

If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/config-load/issues

Contribution

Pull requests are very welcome. Please:

  • ensure all tests pass before submitting PR
  • add an entry to changelog
  • add tests for new features
  • document new functionality/API additions in README

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.1
    1
  • 0.1.0
    0

Package Sidebar

Install

npm i config-load

Weekly Downloads

1

Version

0.1.1

License

none

Last publish

Collaborators

  • overlookmotel