DO NOT USE IT ANYMORE - END OF LIFE
simpleconf is designed for simplicity, well what a suprise by that name...
There are just "//"-comments in the json file allowed and they get removed with a simple RegEX and then parsed with default JSON.parse(). If simpleconf finds another file with the env in it, it will merge the settings.
I needed a simple solution for cascading and commented json files with no or less deps in production a project.
I didn´t find any simple existing solution which allows comments in json and simple cascading, so I wrote simpleconf.
The idea behind cascading config is the following:
you will define the default settings for your application
you will define your production settings (e.g. mysql connection) and you will properly not have this file in git
you will define your stage settings (e.g. mysql connection) and you will properly not have this file in git
you will define your unittest settings (e.g. mysql connection) and you will properly not have this file in git
The developer stahlstift will define the settings for his environment and you will properly not have this file in git
The developer anotherdev will define the settings for his environment and you will properly not have this file in git
If there is a new developer, then you don´t need to change anything in your code for his environment. Also every developer can have his special settings and doesn´t need to commit anything about his setup in git. You can config your stage with different credentials as the live, etc.
Another nice spot about cascading config files is the point that you can define defaults and be sure that they are present.
Time to remove a lot of ulgy "arg = arg || 'defaultvalue';" statements.
You just need to remember that you should run your script with the correct env (if none is given, simpleconfig looks for yourname.development.json)
node yourscript.js NODE_ENV=stage
Install (or add it manually to your package.json):
npm install simpleconf --save
Example directory structure:
config/ config/config.json config/config.development.json
var simpleconf = require('simpleconf'); var env = process.env.NODE_ENV || 'development'; var config = simpleconf(dirname + '/config/config.json', env); console.log(config);
Now every property in config.json is overwritten thru a merge with config.development.json
- 2014-01-11 v1.0.2 Release
How to contribute?
- npm install -g grunt-cli
- grunt (grunt.cmd on windows)
- open a pull request and wait =)
License - "MIT License
Copyright (c) 2013 Markus Lanz (aka stahlstift)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.