hemanth / nmotw.in

Node Module Of The Week
https://nmotw.in
42 stars 7 forks source link

Easiest way to handling env. var-based configuration for everything #38

Open FGRibreau opened 7 years ago

FGRibreau commented 7 years ago

Category: configuration

common-env common-env configuration through environment variables finally done right.

// test.js

const env = require('common-env')();
// also try:
// const env = require('common-env/withLogger')(console);

const config = env.getOrElseAll({
  amqp: {
    login: 'guest',
    password: 'guest',
    host: 'localhost',
    port: 5672
  }
});

console.log(config.amqp.port); // number
AMQP_PORT=1010 node test.js

It's DRY, it follows 12 factors (no configuration files), it supports default values, variable arrays, automatic type conversion, password protection everything that is a constant in your code can use it... easy right?

hemanth commented 7 years ago

Nice, what do you feel about cross-env?

FGRibreau commented 7 years ago

@hemanth both will work together indeed and don't do the same thing :)