env-val
Configuration management using environment-variables, validation & object extension.
Using environment variables in node.js projects including validation, default values & type conversion.
Install
$ npm install env-val --save
Basic Usage
Basic schema
Schemas are loaded by default from all files matching **/*.js
in the directory ./config
.
Define a schema in ./config/logger.js
.
// Load EnvVal to be able to get the exposed joi object.const EnvVal = ; const schema = EnvValjoiobject LOGGER_LEVEL: EnvValjoi LOGGER_ENABLED: EnvValjoi ; const error value: envVars = EnvVal joi ;if error throw `Config validation error: `; const values = envVars; moduleexports = schema values;
Basic initialization of env-val
:
const EnvVal = ; let configs = ; console; // => trueconsole; // => 'info'
Override environment variables:
const EnvVal = ; let configs = LOGGER_ENABLED: false LOGGER_LEVEL: 'warn'configs; console; // => falseconsole; // => 'warn'
By default config files are loaded from the ./config
directory.
This can be customized by passing the CONFIG_DIR
option to the constructor of env-val.
const EnvVal = ;const path = ; let configs = CONFIG_DIR: path
About
Author
Stefan Walther
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. The process for contributing is outlined below:
- Create a fork of the project
- Work on whatever bug or feature you wish
- Create a pull request (PR)
I cannot guarantee that I will merge all PRs but I will evaluate them all.
License
MIT
This file was generated by verb-generate-readme, v0.6.0, on May 08, 2018.