1.0.2 • Published 5 years ago

resm-env v1.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

EnvJs

A wrap service of dotenv utilizing fallback for non existing environment configuration in Nodejs

Prerequisite

Installation

npm install --save resm-env

Usage

Available methods:

  • get(key, defaultValue) - get the specific env key and specify the default value if not existing.
  • set(key, value) - specify additional environment and value.
  • getAndParse(key, defaultValue) - get the specific env key and parse it to get the object. If the value is not a string object, please use the get method instead.
const config = {
    // full path
    path: __dirname + '/.env',
    //optional
    encoding: 'UTF8' //default UTF8
};

const Env = new (require('resm-env'))(config);

Env.get('HOST', 'SampleHost');

const data = [
    {HOST: 'localhost', PORT: 9000}
    {HOST: '127.0.0.1', PORT: 9001}
];
Env.set('HOST_REPLICA', data);

Env.get('HOST_REPLICA', data);

Env.getAndParse('REDIS_REPLICA', `[
    {HOST: 'localhost', PORT: 9000}
    {HOST: '127.0.0.1', PORT: 9001}
]`);

Inspiration.

License

MIT

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago