fine-env
Read environment variables from process.env
(.env
) as convenient nested object.
Store objects and arrays as string variables.
Install
# with npm npm install fine-env # or with yarn yarn add fine-env
Usage
const env = ; // getting environment vars from env object // get PORT const port = envport; // get MONGODB_URL const mongodbUrl = envmongodbUrl; // get GOOGLE__APP_1__CLIENT_ID and GOOGLE__APP1__CLIENT_SECRETconst clientId clientSecret = envgoogleapp1;// or use original keysconst CLIENT_ID CLIENT_SECRET = envgoogleapp1; // get SystemRootconst SystemRoot = env;// or use camelCase styleconst systemRoot = env; // get all vars with prefix GOOGLE__const google = env;// or with requireconst google = ; // get ROOT_VAR__parentVar__child_Varconst childVar = envrootVarparentVar; // get _INIT_UTS__PLATFORM and _INIT_UTS__RELEASEconst db = envdb;const platform release = env_initUts;
Array storage
FOO__BAR__=111,222,333,444,555
ALLOWED_HOSTS__=localhost,example.com,*.example.com
const env = ; console; // => [111, 222, 333, 444, 555]console; // => ['localhost', 'example.com', '*.example.com']
License
MIT