When combining objects from many sources, deep copy is used:
// a
{ sub: { foo: 'foo' }, arr: [ 'foo' ] }
// b
{ sub: { bar: 'bar' }, arr: [ 'bar' ] }
// combined (a + b)
{
sub: { foo: 'foo', bar: 'bar'},
arr: ['foo', 'bar']
}
// E.g you want completely to overwrite `arr` property, then prefix the key's name with `!`// a
{ sub: { foo: 'foo' }, arr: [ 'foo' ] }
// b
{ sub: { bar: 'bar' }, '!arr': [ 'bar' ] }
// combined (a + b)
{
sub: { foo: 'foo', bar: 'bar'},
arr: ['bar']
}
Example:
importAppCfgfrom'appcfg'const config = awaitAppCfg.fetch([
// from file. (with Special Folder format syntax support)
{
path: '%APPDATA%/.appName/config.yml',
// set this source as writable for configuration persistancewritable: true
},
// ENV + .env
{
dotenv: true,
// per default CWD is checked, can be overridenpath: './foo/bar/'
},
// directory
{
path: 'defaults/**.yml'
},
// mongodb
{
mongo: 'barSettings'
},
// from file, but use only nested property
{
path: 'package.json',
getterProperty: 'atma'
}
]);
Command Line overrides
Command line arguments are parsed and also set to the configuration object.
$ node app --foo.bar barValue --debug
let config = awaitConfig.fetch(someSources);
assert.has(config, {
foo: {
bar: 'barValue'
},
debug: true
})
Conditions
Yaml conditions example. (same is also for json format)
Ways to define the variables. (Example defines DEBUG and TEST flags)
directly in the configuration
//foo.ymldebug:truetest:true
from the command line:
> node index --debug --test
using environment configuration(comma delimited)
$ set ENV=DEBUG,TEST
# also
$ set NODE_ENV=DEBUG,TEST
$ node index
.toJSON():Object
Returns clean json configuration object.
.done(callback)
Fire the callback when the configuration is loaded
Source
Common properties for all source types
{
// Define specific property to extract SUB-JSON from the loaded configuration// @default: nullgetterProperty: String// Define specific property in the root configuration,// where the loaded configuration should be inserted into// @default: nullsetterProperty: String// Specify if this source can be used for persistence// @default: falsewritable: Boolean// Fires before source $read function is called// (e.g. change this.path property or any other things)beforeRead: Function<Source, RootConfig>
// Fires after source completes reading// (e.g. access config object in `Source.config`)afterRead: Function<Source, RootConfig>
// If true, do not log any warning if the source returns 404// @default: falseoptional: true// If true, then waits until all previous sources are loaded// @default: falsesync: true
}
FileSource
{
// File pathpath: String
}
DirectorySource
It will be mapped to multiple FileSources
{
// Directory path with GLOB look-up, e.g. 'configs/**.json'path: String
}
MongoDBSource
Depends on ClassJS
{
// Collection namemongo: String,
// if source is writable// @default: truewritable: Boolean// MongoDB Connection Settings// It can be also specified in previous configuration source, under `mongodb` property// @default: null -settings: {
// connection stringconnection: String// or// Port, default 27017port: Number,
// IP, default '127.0.0.1'ip: String,
// Database name, no defaultdb: String
}
}
CustomSource
This source type can suit any needs.
// Constructor with the Deferrable Interface and the method `read`FunctionclassFoo {
config: any
async read (){
// do any reads and calcs, after that resolve the sourcethis.config = awaitloadConfig();
}
}
The npm package appcfg receives a total of 2,643 weekly downloads. As such, appcfg popularity was classified as popular.
We found that appcfg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 0 open source maintainers collaborating on the project.
Package last updated on 18 Jul 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.