This is a nodejs module to allow management of persistent and environment variable configuration.
The module can be added to your project with:
npm install @adobe/aio-lib-core-config --save
Here is a snippet:
const config = require('@adobe/aio-lib-core-config')
// set a key value
config.set('pgb.authtoken', 1234)
// reload data from files and environmental variables
config.reload()
// get all stored data
config.get()
// get data from a given key
config.get('pgb.authtoken')
// delete a key
config.delete('pgb.authtoken')
The user default location is:
- ENV['AIO_CONFIG_FILE']
- ENV['XDG_CONFIG_HOME']/aio
- <HOME>/.config/aio
depending on whether the specified environmental variables exist
Local configuration is loaded from $PWD/.aio
A local .env file is also loaded. This file can contain environmental variables.
Note: All environment variable names will be converted to uppercase.
- In the event that there are duplicate environment variables, if the uppercase version exists, it will be hoisted.
aa=1
aA=2
AA=3 <-- Hoisted as AA
- In the event that there are duplicate environment variables with multiple case variations, the first entry will be hoisted.
aa=1 <-- Hoisted as AA
Aa=2
Resolving configuration is done in two steps:
- .env file is read, parsed and hoisted to environment variables ( process.env )
- user and local files are read
Inheritance is similar to NPMRC and can be set using user file, project file and matching environment variables. Values are read and merged in the following order in increasing priority:
- user config eg. ~/.config/aio
- project config eg. $PWD/.aio
- environment variables matching AIO_<PLUGIN>_<KEY>
$ AIO_PGB_AUTHTOKEN=1234 node
> config.get('pgb.authtoken')
1234
$ AIO_PGB_AUTH__TOKEN=1234 node # use double underscores to specify an underscore
> config.get('pgb.auth_token')
1234
goto
API
Contributions are welcomed! Read the Contributing Guide for more information.
This project is licensed under the Apache V2 License. See LICENSE for more information.