1.2.1 • Published 6 years ago
@totemish/env v1.2.1
Env
Totemish ENV wraps up your NodeJS process.env
and process.argv
into something convenient and immutable (sort of).
Installation
npm i --save @totemish/env
Usage
Simply instantiate the Environment
class and you are good to go. Features:
process.env
It automatically eats your .env
file if you haven't specified NODE_ENV to be equal to production
.
// NODE_ENV=production node index
import { Environment } from '@totemish/env';
const env = new Environment();
console.log(env.hasEnvKey('NODE_ENV')); // true
console.log(env.env.NODE_ENV); // 'production'
process.argv
- kwargs:
// node index --a=b --b c -c=d -d f
import { Environment } from '@totemish/env';
const env = new Environment();
console.log(env.kwargs); // { a: 'b', b: 'c', c: 'd', d: 'e' }
console.log(env.hasKwargs()); // true
console.log(env.hasKwargKey('a')); // true
console.log(env.getKwarg('b')); // 'c'
- flags:
// node index --flagged
import { Environment } from '@totemish/env';
const env = new Environment();
console.log(env.flags); // [ 'flagged' ]
console.log(env.hasFlags()); // true
console.log(env.hasFlag('flagged')); // true
- args:
// node index myArg myArg2
import { Environment } from '@totemish/env';
const env = new Environment();
console.log(env.args); // [ 'myArg', 'myArg2' ]
console.log(env.hasArgs()); // true
console.log(env.hasArg('myArg')); // true
Usage with @totemish/injector
// node index --injectionSuccess
import { Environment } from '@totemish/env';
import { Container } from '@totemish/injector';
Container.register(Environment, 'env');
console.log(Container.get('env').hasFlag('injectionSuccess')); // true