A small, simple and dependency-free library for configuration
Do not use default.js
for development values that are different in other environments. In other words: only use default.js
for values that are the same for all environments.
Add local.js
to your .gitignore
file.
Define a configuration file
// config/test.js
module.exports = {
my_config_value: 'test'
}
Use the configuration
// index.js
const { my_config_value } = require('@kaliber/config')
console.log(my_config_value)
Run the command with the correct environment
CONFIG_ENV=test node index.js
Define a configuration file
// config/test.js
module.exports = {
my_config_value: 'test'
}
Load the configuration
// index.js
const load = require('@kaliber/config/load')
const { my_config_value } = load('test')
console.log(my_config_value)
Define a configuration file
// config/test.js
module.exports = {
my_config_value: 'test'
}
Run the command with the correct environment
./node_modules/.bin/kaliber-config test my_config_value
When running in an NPM environment (scripts
in package.json
):
kaliber-config test my_config_value
Order:
default.js
${CONFIG_ENV}.js
local.js
So any value from local.js
will override a value from one of the previous configuration files.
Any nested objects will be combined.
We used the config npm package but ran into trouble with out staging/acceptance environment. In that environment we wanted to compile with NODE_ENV=production
for performance benefits of certain libraries.
We also ran into trouble when we forgot to set an environment variable, the config
library provided a default instead of throwing an error.
Another motivation was that we only needed a very simple library, the config
library is 1750 line file full of usefull options that we did not need.