A better way to load big json config files in node.js apps
Sometimes config files grow to sizes that are difficult to handle, therefore it is desirable to distribute information in different files and folders.
If you hand out your config in files inside a folder named as your main json config file, deepjson will populate it with this folder data. deepjson will also extend this object with the following files (and its trees) that you have passed as arguments.
.jsons and folders structure:
{ "appName": "MyApp", "port": 3000 }
{ "port": 4444 }
{ "description": "We load configs" }
[ "a", "big", "array" ]
var deepjson = require( 'deepjson' );
var defaultConfig = deepjson( 'default' );
/* {
appname: 'MyApp',
port: 3000,
SEO: {
description: 'We load configs',
keywords: ['a', 'big', 'array']
}
} */
var productionConfig = deepjson( 'default', 'production' );
/* {
appname: 'MyApp',
port: 4444,
SEO: {
description: 'We load configs',
keywords: ['a', 'big', 'array']
}
} */
Install with npm
$ npm install deepjson
Load all the json files passed as arguments, then extend them with json files under the folders with same name. Deepjson will return a object result of extend loaded files in order.
Parameters:
npm install && npm test
© 2015 Jacobo Tabernero
Released under MIT License