Giter VIP home page Giter VIP logo

exportconfig's Introduction

Export Config

This is a small module to help developers to manage their App's configuration. The idea is to be able to have one config file for each concern/subject in your system.

Organizing your configuration this way you can easily find what you are looking for without searching through different files for each environment. But we should also be able to import seemlessly this configurations in the App, to avoid poluting the code and to not confuse the dev team. It should be easy as require('./config/database');.

Example

// config/database
'use strict';

const exportConfig = require('export-config');

const DatabaseConfig = {
  default: {
    RECONNECT_TRIES: 3,
    RECONNECT_INTERVAL: 1000,
    AUTO_RECONNECT: true,
    BUFFER_MAX_ENTRIES: 0,
    SCHEDULE_TIMEOUT: 7200000
  },
  development: {
    URI: 'mongodb://localhost/dev_db'
  },
  staging: {
    URI: 'mongodb://localhost/test'
  },
  production: {
    URI: 'mongodb://243.123.63.10/prod_db_01',
    RECONNECT_TRIES: 4,
    RECONNECT_INTERVAL: 1500
  }
}

module.exports = exportConfig(DatabaseConfig);
// index.js

const DatabaseConfig = require('./config/database');

console.log(DatabaseConfig);
/**
 * If we have not set the process.env.NODE_ENV variable, it will print:
 * {
 *   RECONNECT_TRIES: 3,
 *   RECONNECT_INTERVAL: 1000,
 *   AUTO_RECONNECT: true,
 *   BUFFER_MAX_ENTRIES: 0,
 *   SCHEDULE_TIMEOUT: 7200000,
 *   URI: 'mongodb://localhost/dev_db'
 * }
 *
 * But if we have set the process.env.NODE_ENV to 'production'
 * {
 *   RECONNECT_TRIES: 4,
 *   RECONNECT_INTERVAL: 1500,
 *   AUTO_RECONNECT: true,
 *   BUFFER_MAX_ENTRIES: 0,
 *   SCHEDULE_TIMEOUT: 7200000,
 *   URI: 'mongodb://243.123.63.10/prod_db_01'
 * }
 */

This way we can arrange our configuration files as:

+-- config
|   +-- mongo.js
|   +-- redis.js
|   +-- ghost.js
|   +-- googleCalendar.js
|   ...
+-- index.js

And import each configuration file separetly nicely and seemlessly as require('./config/mongo.js').

exportconfig's People

Contributors

andrebot avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

israeldahan

exportconfig's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.