What is it?
This module is simple, no dependencies environment and cli parser used for parsing arguments from commands, properties from config and variables from environment. Envfull loads data from this sources and merge it together into one result.
- Load variables from
.envfile and enrich this data from
process.env. This will create object with environmental variables loaded from file and from environment.
- Load data from config (if you provided path to config). This will create object with variables
from your config. Actual supported configs are:
- Load data from command line arguments and create object with variables and rest of items on command line.
- Merge these data with this order (env, config, command line) into one object, enrich this object by defined defaults values and return it.
With npm do:
npm install envfull
Types and types resolving
9999 in variables, it will be typed as
Number. If here is
false it will be typed
as boolean. Same this has happend with command line arguments with same name. If you use
--only 1 --only 2 Envfull make results as array
[1, 2]. But if you use only
--only 1 variable
will be presented as number
1. Because of it, you can force force typed on same keys. More
info you can read below in section Options - forced types
You can try ENVFULL playground on repl.it!
Test envfull and check if you can use it in your app. Live example with predefined command line arguments can help you too understand how envfull is working.
More examples can be found here! And if you want to add new one, just make and merge request and add your example to help others.
Typescript usage example
;//without any settings;
;//calling with json config;
;//with basic settings;
console.logparsed.$; //Object tree with variables, merged from environmental variables alsoconsole.logparsed._; //Rest of items on command-lineconsole.logparsed; //No parsed data after -- in command line
const envfull = envfull;const parsed = ;
;//calling with json config;
const envfull = envfull;//with basic settingsconst parsed =;
console; //Object tree with variables, merged from environmental variables alsoconsole; //Rest of items on command-lineconsole; //No parsed data after -- in command line
opts.env: Array<string | RegExp>
List of all variables or regular expresion for variables name that will be import from ENV store on NodeJS. For example if you will be used only "APP.USERNAME" and "APP.TOKEN" in you app, you can use
const opts =env: "APP.USERNAME" "APP.TOKEN"
or with using RegExp
const opts =env: /APP\.[A-Za-z0-9]/
Envfull will load only these variables from ENV store and rest will be ignored. By default all ENV variables are imported.
opts.aliases: Partial<T> | Object
This are aliases for some variables. Aliases are defined by partial object structure or you can
define it like object mapping where levels are split by
Sou you can defined aliases by
const opts =aliases:db:host: "APP.DB.HOST"port: "APP.DB.PORT"
or you can use string maps version of aliases
const opts =aliases:"db.host": "APP.DB.HOST""db.port": "APP.DB.PORT"
Both are valid settings, but if you use typescript, first version is recommended, because typescript will be showing properties of object.
opts.defaults: Partial | Object
Default values for variables that are missing. If you not specified variables in command line, config
or in ENVIRONMENTS variables, envfull will use this default and fill results objects. Defaults are
defined by partial object structure or you can define it like object mapping where levels are
Sou you can defined defaults by
const opts =defaults:db:host: ""port: 3333
or you can use string maps version of defaults
const opts =defaults:"db.host": """db.port": 3333
Options - forced types
You can force type on specified variables. Keys defined on settings will be always converted into
specified typed value even if is not in right type. For example
db.port will be always number, so
if you send value
"test", this variable will have value
"test" is can not be converted
to number. Same is with other types.
const opts =strings: "db.host"numbers: "db.port"booleans: "db.test"arrays: "only"
Donate me 😉
MIT - MIT License