resin-io/conf.js

Name: conf.js

Owner: Resin.io

Description: Support per-user and per-project configuration files out of the box.

Created: 2014-12-11 14:58:40.0

Updated: 2017-03-06 13:28:47.0

Pushed: 2015-08-07 13:44:11.0

Homepage:

Size: 260

Language: CoffeeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

conf.js

npm version dependencies Build Status Build status

conf.js allows you to get per-user and per-project configuration files out of the box.

Look how easy it is to use:

ttings.coffee
 = require('path')
JS = require('conf.js')

le.exports = new ConfJS
userConfig: path.join(process.env.HOME, '.myprojectrc.json')
localConfig: '.myprojectrc.json'
default:

    # Your usual application settings
    port: '9999'
    name: 'My cool app!'
    ...

Now if $HOME/.myprojecrc exists, it's settings will override the defaults.

If then create a .myprojecrc file inside one of your projects directory and run the application from within that directory, the contents will override $HOME/.myprojecrc and defaults.

Notice that you can set a custom local configuration file within your user configuration and it'll be correctly used.

You can now get/set your settings with:

ings = require('./settings')
ings.get('port') # 9999
ings.set('name', 'My really cool app!')
Features

Specify userConfig to the user configuration file path.

Specify localConfig to the local configuration file name.

Installation

Install conf.js by running:

m install --save conf.js
Methods
constructor(options)

Create an instance of settings.

The following options are accepted:

settings.extendWithFile(file)

Extend setting with the contents of a file.

settings.set(key, value)

Set runtime value of a setting, or create a new one.

Notice you can set nested keys:

ings.set('my.nested.key', 'value')
settings.get(key)

Get the value of a setting.

Notice you can get nested keys:

ings.get('my.nested.key')

If you pass no key to settings.get(), then you will get back all the settings.

settings.has(key)

Check if settings has a specific key.

settings.extend(objects…)

Extend settings with object/s.

settings.isEmpty()

Check if settings object is empty.

settings.parse(input)

Parse input given a function passed to options.parse.

Tests

Run the test suite by doing:

lp test
Contribute

Before submitting a PR, please make sure that you include tests, and that coffeelint runs without any warning:

lp lint
Support

If you are having any problem, please raise an issue.

TODO
ChangeLog
v1.1.1
v1.1.0
License

The project is licensed under the MIT license.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.