Skip to content

Configuration framework to help with large amount of configurations.

License

Notifications You must be signed in to change notification settings

opentable/spur-config

Repository files navigation

Spur: Config

Configuration framework to help manage complex application configurations in Node.js.

NPM Version NPM Install Size NPM Downloads

About the Spur Framework

The Spur Framework is a collection of commonly used Node.JS libraries used to create common application types with shared libraries.

Visit NPMJS.org for a full list of Spur Framework libraries >>

Topics

Quick start

Installing

Standalone:

$ npm install spur-config --save

With dependency injection:

$ npm install spur-ioc --save
$ npm install spur-common --save
$ npm install spur-config --save

Usage

Supports active Node versions in the LTS Schedule. (view current versions)

Configuration files

src/config/default.js

module.exports = function () {

  return this.properties({
    environment: 'default',
    port: 8080
  });

}

src/config/shared-deployed.js

module.exports = function () {

  return this.properties({
    shared: {
      someProp: 123
    }
  });

}

src/config/development.js (default)

module.exports = function () {

  this.extends('default');

  return this.properties({
    environment: 'default'
  });

}

src/config/production.js

module.exports = function () {

  // Extend multiple files
  this.extends('default', 'shared-deployed');

  return this.properties({
    environment: 'production',
    port: process.env.PORT or 9000
  });

}

Standalone use

This example shows how to manually load configuration into

const spurConfig = require('spur-config');

const configDirectory = path.join(__dirname, 'src/config');

// load specific environment file
const config = SpurConfig.load(configDirectory, 'production');

// loads configuration specified in NODE_ENV environment variable
const config = SpurConfig.load(configDirectory);

With spur-ioc auto-registration

This example loads the configuration into an injector/module and makes it available as the config dependency.

src/injector.js

const spur = require('spur-ioc');
const spurConfig = require('spur-config');
const registerConfig = require('spur-common/registerConfig');

module.exports = function () {

  const ioc = spur.create('test-application');
  const configDirectory = path.join(__dirname, './config');

  registerConfig(ioc, configDirectory);

  return ioc;
}

src/services/TestConfig.js

module.exports = function (config) {

  console.log(config);

}

Contributing

We accept pull requests

Please send in pull requests and they will be reviewed in a timely manner. Please review this generic guide to submitting a good pull requests. The only things we ask in addition are the following:

  • Please submit small pull requests
  • Provide a good description of the changes
  • Code changes must include tests
  • Be nice to each other in comments. 😇

Style guide

The majority of the settings are controlled using an EditorConfig configuration file. To use it please download a plugin for your editor of choice.

In addition we use ESLint to enforce some of the JavaScript rules. To enable on your editor, please install one of the editor plugins.

If your editor does not have ESLint integration, the test commands below will run them and fail your build.

All tests should pass

Execute the following the install the dependencies, build and test with the following.

$ npm install
$ npm test

View the package.json's scripts section for a list of all the other commands.

License

MIT