@4c/env
A small set of utils for working with environment variables in node and webpack projects. Wraps the excellent getEnv
as well
Usage
import * as Env from '@4c/env';
Getting and parsing variables
env
wraps and reexports getEnv
as get()
.
Env.get('NODE_ENV');
Env.get('NOT_SET_VAR');
Env.get('NOT_SET_VAR', 'default_value');
Env.get.int('MAX_SUBSCRIPTIONS', 4);
process.env.BOOLISH = 1;
Env.get.boolish('BOOLISH');
Loading .env
files
env
will load and parse .env
files, by environment. We use the naming convention variables-{ENV}.env
to split out variables by different environment. The default is dev
.
Env.load();
Env.load('test');
There is also a utility for passing enviroment variables to webpack's DefinePlugin
allowing instances of process.env.FOO
in front-end code to be replaced with a specific compile-time value.
new webpack.DefinePlugin(Env.define('test'));