Skip to content
Simple feature flipper module for Node.js
JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib pass file contents back to callback when update detected Jan 16, 2014
tests guarantee clean cache prior to tests Jun 25, 2015
.codeclimate.yml prune and optimize code climate configuration Sep 24, 2015
.gitignore
.npmignore ignore wercker config during npm publish Jul 17, 2014
.travis.yml enable builds for v0.12 Jun 23, 2015
DEV.md update documenation & dev notes Sep 24, 2015
LICENSE Initial commit Jan 15, 2014
README.md update documenation & dev notes Sep 24, 2015
index.js Make load callback optional May 25, 2015
package.json migrate test framework over to Mocha Jul 2, 2015
wercker.yml deploy code coverage to code climate Sep 24, 2015

README.md

Build Status Coverage Status wercker status Code Climate

flipit

A module that allows you to use feature flags (also known as feature flipping) in Node.js.

You can enable/disable features programmatically or via an external configuration file. Any changes to the configuration file will update the module without requiring a restart.

Configuration File

Optionally, the flipit module can load a JSON file that contains the feature flags/switches, as well as their initial state.

{
    "testFeature": true,
    "anotherFeatureForTesting": true,
    "thisShouldBeUnavailable": false
}

Example Usage

var flipit = require('flipit'),
	result;

flipit.load('testConfigurationFile.json');

result = flipit.isEnabled('testFeature');
console.log(result);    // true

result = flipit.isEnabled('thisShouldBeUnavailable');
console.log(result);    // false

flipit.disable('testFeature');
result = flipit.isEnabled('testFeature');
console.log(result);    // false

flipit.enable('thisShouldBeUnavailable');
result = flipit.isEnabled('thisShouldBeUnavailable');
console.log(result);    // true

API

load('filepathToJsonFile', [callback])

Loads a JSON file containing an object of key-value pairs.

  • 'filepathToJsonFile': The absolute path to the JSON configuration file.
  • callback: Optional. The flipit module will detect any updates made to the given JSON file. After the state of the feature flags/switches has been updated, the callback will be triggered.

Returns a fs.FSWatcher object. For reference: Node.JS API document.

isEnabled('featureName')

Checks if a given feature 'featureName' is enabled.

  • 'featureName': The name of the feature flag/switch. If loaded from a JSON configuration file, this will be the name of the key.

Returns true or false, whether the feature flag/switch is (respectively) enabled or disabled.

disable('featureName')

Disables a given feature 'featureName'. Calling flipit.disable() with a feature that is already disabled is a no-op, not an error.

  • 'featureName': The name of the feature flag/switch. If loaded from a JSON configuration file, this will be the name of the key.

Returns nothing.

enable('featureName')

Enables a given feature 'featureName'. Calling flipit.enable() with a feature that is already enabled is a no-op, not an error.

  • 'featureName': The name of the feature flag/switch. If loaded from a JSON configuration file, this will be the name of the key.

Returns nothing.

You can’t perform that action at this time.