Git Product home page Git Product logo

a.config's Introduction

a.config - Node.js config system

Configuration system for Node.js Applications

Introduction

Configuration system created for systematization of the configuration files. You can simply extend, edit and monipalte yours configs.

Wiki pages

Usage

Install using npm

project$ npm install a.config

You can write yours configs in js, json, yaml.

Example config file

# Inner vars
$config:

  default.format.processor: 'default'
  default.format.value: '%level %date %args %code'

  production:
    mongo:
      uri: 'mongodb://localhost.loc:27017/log'
      ttl: 604800
      format:
        name: 'mongo'
        value: '%level, %module, %hostname, %args, %code, %trace, %errors'

  development:
    $extend: production # Extend production and change mongo.uri, mongo.ttl
    mongo:
      uri: 'mongodb://localhost:27017/log'
      ttl: 600

  prog12:
    $extend: development # Extend development and change mongo.uri
    mongo:
      uri: 'mongodb://localhost:27030/log'

# Logger System Configurations
default:
  all:
    console: true
    syslog: true

production:
  $extend: default # Extend default and append app property
  app:
    all,info,debug:
      - mongo:
         $extend: :$config.production.mongo # Extend $config.production.mongo
      - console: true
    error,warn:
      - mongo:
         $extend: :$config.production.mongo # Extend $config.production.mongo
        syslog: true
      - console: true
development:
  $extend: default # Extend default and update app property
  app:
    $replace: :production.app # Extend from production.app, with full change same properties
    all,info,debug:
      - console: true  

Load configuration file

var config = require('a.config');
config.load(__dirname + '/config.yaml');

After config loading you can use this in all application

var config = require('a.config');
console.log(config.default.all);

//{console: true, syslog: true}

For creation new instance of config object and load different config use newInstance()

var config = require('a.config');
config.load(__dirname + '/config.yaml');

var exConfig = config.newInstance();
exConfig.load(__dirname + '/config.ex.yaml');

console.log(config.default.all);
//{console: true, syslog: true}

console.log(exConfig.default);
//undefined

Extends

For convenient use configurations used rashireniem:

  • $extend - Extend current object, you must specify the name of the object. You can use local name(objects in same level) or name from root. For root location use : before name of object.

    Example

	production:
	  mongo:
	    uri: 'mongodb://localhost.loc:27017/log'
	    ttl: 604800
	    format:
	      name: 'mongo'
	      value: '%level, %module, %hostname, %args, %code, %trace, %errors'
	
	development:
	  $extend: production
	  mongo:
	    uri: 'mongodb://localhost:27017/log'
	    ttl: 600
	
	user:
	  mongo:
	    $extend: :production.mongo
{
    "production": {
        "mongo": {
            "uri": "mongodb://localhost.loc:27017/log",
            "ttl": 604800,
            "format": {
                "name": "mongo",
                "value": "%level, %module, %hostname, %args, %code, %trace, %errors"
            }
        }
    },
    "development": {
        "mongo": {
            "uri": "mongodb://localhost:27017/log",
            "ttl": 600,
            "format": {
                "name": "mongo",
                "value": "%level, %module, %hostname, %args, %code, %trace, %errors"
            }
        }
    },
    "user": {
        "mongo": {
            "uri": "mongodb://localhost.loc:27017/log",
            "ttl": 604800,
            "format": {
                "name": "mongo",
                "value": "%level, %module, %hostname, %args, %code, %trace, %errors"
            }
        }
    }
}
  • $replace - Same as $extend, but it will rewrite all object

    Example

	production:
	  mongo:
	    uri: 'mongodb://localhost.loc:27017/log'
	    ttl: 604800
	    format:
	      name: 'mongo'
	      value: '%level, %module, %hostname, %args, %code, %trace, %errors'
	
	user:
	  mongo:
	    $replace: :production.mongo
	    format:
	      caption: 'caption'
{
    "production": {
        "mongo": {
            "uri": "mongodb://localhost.loc:27017/log",
            "ttl": 604800,
            "format": {
                "name": "mongo",
                "value": "%level, %module, %hostname, %args, %code, %trace, %errors"
            }
        }
    },
    "user": {
        "mongo": {
            "format": {
                "caption": "caption"
            },
            "uri": "mongodb://localhost.loc:27017/log",
            "ttl": 604800
        }
    }
}
  • $include - Include some else file into current object. Use path relative to the current config

    Example

	production:
	  mongo:
	    uri: 'mongodb://localhost.loc:27017/log'
	    ttl: 604800
	    format:
	      name: 'mongo'
	      value: '%level, %module, %hostname, %args, %code, %trace, %errors'
	
	user:
	  mongo:
	    $include: './configs/mongo.yaml'

License

May be freely distributed under the MIT license

See LICENSE file

Copyright (c) 2013 - Sumskoy Andrew [email protected]

a.config's People

Contributors

a696385 avatar

Stargazers

Matthew avatar

Watchers

James Cloos avatar  avatar

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.