This content originally appeared on DEV Community and was authored by SiegfredRodriguez
I finally dipped my toes in opensource, with my simple unopinionated yet capable configuration utility config-discovery!
- Will not force you on any conventions such as directory and specific files.
- Uses fluent interface, no strange incantations.
- Fit for containerized deployments where configurations maybe split between ConfigMaps and Secrets.
Some of its features include the ability to define a source priority for your configuration, including environment and directly from an object!
let Config = require('config-discovery');
....
let configuration = new Config()
.fromFile('/configs/config.json')
.orFile('/configuration/config.json')
.orFile('/etc/my_configs/config.json')
.orEnv(prototype)
.orObj(configObject)
.get();
Compose a configuration from multiple sources, including the environment!
let prototype = {user: 'DB_USERNAME', password: 'DB_PASSWORD'}
let configuration = new Config()
.fromFile('/configs/config.json')
.orFile('/configuration/config.json')
.orFile('/etc/my_configs/config.json')
.thenPatchWith()
.env(prototype)
.get();
// or from another file
let configuration = new Config()
.fromFile('/configs/config.json')
.orFile('/configuration/config.json')
.orFile('/etc/my_configs/config.json')
.thenPatchWith()
.configFile(/etc/secrets/credentials.json)
.get();
// or from another object
let configuration = new Config()
.fromFile('/configs/config.json')
.orFile('/configuration/config.json')
.orFile('/etc/my_configs/config.json')
.thenPatchWith()
.object(secretsJson)
.get();
This content originally appeared on DEV Community and was authored by SiegfredRodriguez
SiegfredRodriguez | Sciencx (2021-09-04T15:43:24+00:00) A simple yet handy configuration compositor and locator!. Retrieved from https://www.scien.cx/2021/09/04/a-simple-yet-handy-configuration-compositor-and-locator/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.