4.0.1 • Published 4 years ago

pony-config v4.0.1

Weekly downloads
239
License
-
Repository
github
Last release
4 years ago

pony-config

Build Status Coverage Status Known Vulnerabilities

Versatile, Predictable Configuration

config.get('best.configuration.library')

Configuration can be combined from many sources

  • JSON files
  • Command Line Arguments
  • Javascript Objects
  • Environment Variables
  • Programmatically

Configuration sources are merged predictably

  • Config properties are extended and replaced recursively
  • Powerful debug trace of each config value's source
  • Makes it easy to set defaults, load common configurations, and override with environment specific config.

Configuration is easily accessed through dot paths

Both get and set methods support dot paths, for example get('name.first')

Different Configuration for each Run-Time Environment

Configuration can be selected at run-time for each of your environments, for example Production, Stage, Dev, Dev-Josh, Dev-Scott.

The run-time environment is determined by searching file paths and environment variables.

config.findRuntimeEnvironment({
    paths:['./env-file'],
    env: 'ENVIRONMENT',
    default:'prod');

Sources can be applied in layers

var config = require('pony-config');

config
.file('common-config.json')                 // common for all environments
.when('test').file('local-config.json');    // test only configuration

See more examples here.

Getting Started

npm install --save pony-config

The config module is a singleton. Set up your configuration in your main file at startup, access it everywhere in your project.

var config = require('pony-config');

See the api documentation for the full pony-config API documentation.

Debugging

pony-conifg provides several tools to help you debug your configuration. See the debugging documentation for the debug API.

Secure Keys

Always store key files outside of your repo

In production, keys are often served to applications through environment variables, while locally keys live on the file system. To keep keys safe, store them outside your repo, for example, in ~/keys/ and use pony-config to load the appropriate key.

config
    .when('dev').file('~/keys/secret.key')
    .when('prod').env( 'secret', 'SECRET_API_KEY')

See Also

pony-config uses

  • minimist for command line argument parsing because it does exactly one thing and does it well.
  • fs-coalesce to search file paths. This module (also by ponycode) extends the file path syntax to include '~', and automatically matches on the first extant file in an array of paths.

Tests

npm test

For coverage, run npm run coverage


License

Copyright (c) 2014,2020 PonyCode Corporation Licensed under the MIT license.

4.0.1

4 years ago

4.0.0

4 years ago

3.1.1

6 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

8 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1-n

9 years ago

1.0.0

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago