0.7.0 • Published 6 years ago

affecto v0.7.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
6 years ago

Configure your Node.js Applications

Build Status codecov

js-standard-style

Introduction

Affecto organizes hierarchical configurations for your app deployments. Regardless of whether the configuration file is located at one or more locations.

It lets you define a set of default parameters, and extend them for different deployment environments (development, qa, staging, production, etc.).

How it works

By default, Affecto search the project directory for configuration files. All files containing .config in the name are recognized as configuration files. The filename should have one of the supported file extensions, such as .json or .yml. In addition, the file should contain one of the keywords for the environment (development, test, production, etc.) in which it should be used, or stage keywords such as default, local or env.

Example file name dbconnect.default.config.json

The values of the various configuration files are read and overwritten or supplemented by the others.
The sequence is:

*.default.config.json -> *.(NODE_ENV).config.json -> *.local.config.json -> *.env.config.json

Quick Start

The following examples are in JSON format, but configurations can be in other. Supported file extensions

Install in your app directory, and create first config file

$ npm install affecto
$ vi services.default.config.json
{
  // services configs
  "services": {
    "dbConfig": {
      "host": "localhost",
      "port": 5984,
      "dbName": "customers"
    },
    "amqp": {
      "connect": "amqp://localhost"
    }
  }
}

Edit config overrides for production deployment:

 $ vi services.production.config.json
{
  "services": {
    "dbConfig": {
      "host": "prod-db-server"
    },
    "amqp": {
      "connect": "amqp://prod-amqp-server"
    }
  }
}

Use configs in your code:

const Affecto = require('affect');
const affector.load();
//...
const dbConfig = affector.get('services.dbConfig');
db.connect(dbConfig, ...);

config.get() will return false for undefined keys.

Start your app server

$ export NODE_ENV=production
$ node my-app.js

Running in this configuration, the port and dbName elements of dbConfig will come from the services.default.config.json file, and the host element will come from the services.production.config.json override file.

Supported file extensions

Currently these file extensions / formats are supported

  • json
  • yaml
  • yml
  • js

Support for the following expansions is in planning

  • hjson
  • json5

Documentation

0.7.0

6 years ago

0.6.2

6 years ago

0.6.0

6 years ago