A simple yet handy configuration compositor and locator!

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 f…


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.

Github
NPMJS

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » A simple yet handy configuration compositor and locator!." SiegfredRodriguez | Sciencx - Saturday September 4, 2021, https://www.scien.cx/2021/09/04/a-simple-yet-handy-configuration-compositor-and-locator/
HARVARD
SiegfredRodriguez | Sciencx Saturday September 4, 2021 » A simple yet handy configuration compositor and locator!., viewed ,<https://www.scien.cx/2021/09/04/a-simple-yet-handy-configuration-compositor-and-locator/>
VANCOUVER
SiegfredRodriguez | Sciencx - » A simple yet handy configuration compositor and locator!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/04/a-simple-yet-handy-configuration-compositor-and-locator/
CHICAGO
" » A simple yet handy configuration compositor and locator!." SiegfredRodriguez | Sciencx - Accessed . https://www.scien.cx/2021/09/04/a-simple-yet-handy-configuration-compositor-and-locator/
IEEE
" » A simple yet handy configuration compositor and locator!." SiegfredRodriguez | Sciencx [Online]. Available: https://www.scien.cx/2021/09/04/a-simple-yet-handy-configuration-compositor-and-locator/. [Accessed: ]
rf:citation
» A simple yet handy configuration compositor and locator! | SiegfredRodriguez | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.