everyconfig
v1.0.2
Published
Use the same yaml config files in every language
Readme
everyconfig
Use the same .yaml config files in every programming language
usage
Set up your config files in a directory like this:
.
├── config
| ├── default.yaml
| ├── production.yaml
| └── test.yaml
├── foo
| ├── foo.js
| └── blue.js
└── bar
├── something.py
└── post.pyThen set CONFIG_ENV to one of the names of your yaml files, like so: CONFIG_ENV=production node app.js
The best part is that all of your configs inherit the default values from default.yaml.
default.yaml:
db:
url: 'localhost'
port: 27017production.yaml:
db:
url: 'some.internal.dns'resulting config for CONFIG_ENV=production:
db:
url: 'some.internal.dns'
port: 27017node.js
var config = require('everyconfig')('./config')
console.log(config.mongodb.url)(note that you can use NODE_ENV instead of CONFIG_ENV with node.js if you want)
python
from everyconfig import everyconfig
config = everyconfig('./config')
print config.mongodb.urlruby
require 'everyconfig'
config = Everyconfig.load('./config')
puts c['mongodb']['url']bash
from https://gist.github.com/pkuczynski/8665367 (note that if you use four space indents, your variables will be separated by two underscores instead of one)
everyconfig <config dir> <variable prefix>source $path_to_everyconfig/bash/everyconfig.sh
# you should use an absolute path for the directory that holds your config files
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# directory prefix
everyconfig "$DIR"/../config CONFIG_
echo $CONFIG_mongodb_urlcontact me
Send me a pr or an email 😀
