There are three different ways to pass options to your config instance.
- Through a local file called
config-settings.json
- Through environment variables
- Through command line arguments
The most robust of these is config-settings.json
.
All available options are optional.
interface IConfigSettings {
configPath?: string
configEnv?: string
remoteOptions?: { [name: string]: any }
resolvers?: Array<string>
loaders?: Array<string>
translators?: Array<string>
schema?: ISchemaMap
}
type: string
Path to local configuration files. By default DynamicConfig
will look for a directory called config
in your project. It will search in predictable places. It will first look at the project root. It will then search for the config
directory in src
, lib
, main
, dist
and app
.
type: string
By default DynamicConfig
will check NODE_ENV
to determine the current environment. This option will override that.
type: object
These are options that will be passed to remote resolvers. The options are of the following form:
interface IRemoteOptions {
[name: string]: any
}
Here the key is the name of the resolver, then when the resolver is instantiated the value here is passed to the initialization of the resolver.
type: Array<string>
This is a list of the Resolvers to use (more on this later).
The included Resolvers are:
env
- Allows reading of environment variablesprocess
- Allows reading of command line argsconsul
- Allows fetching of remote data from Consulvault
- Allows fetching of remote data from Vault
type: Array<string>
This is a list of FileLoaders to use (more on this later).
The included FileLoaders are:
json
- Read JSON files ending with.json
yaml
- Read YAML files ending with.yml
or.yaml
js
- Read JavaScript files ending with.js
ts
- Read TypeScript files ending with.ts
type: Array<string>
List of Translators to user. Translators can finese data into a form expected by Dyanmic Config (more on this later).
The included Translators are:
env
- Allows usage of environment variables of the formhttp://${HOSTNAME}:8080'
consul
- Allos usage ofconsul!
urls.
type: ISchemaMap
A map of key names to JSON schema to validate that key.
interface ISchemaMap {
[key: string]: object
}
If for instance I wanted to change the path to my local config files I would add a new file config-settings.json
and add something like this:
{
"configPath": "./source/config"
}
Additionally, if I wanted to only include the resolvers for env
and process
and support for only json
files:
{
"configPath": "./source/config",
"resolvers": [ "env", "process" ],
"loaders": [ "json" ]
}
Only configPath
, under the name CONFIG_PATH
, and configEnv
, under the name CONFIG_ENV
, can be set with environment variables.
$ export CONFIG_PATH=source/config
$ export CONFIG_ENV=development
Note: Some plugins, as is the case with the Consul Resolver, may support additional environment variables
The command line supports the same subset of options as environemnt variables
$ node ./dist/index.js CONFIG_PATH=source/config CONFIG_ENV=development
Note: Some plugins, as is the case with the Consul Resolver, may support additional command line arguments