flipit
======

[![Build Status](https://travis-ci.org/FenrirUnbound/flipit.png?branch=master)](https://travis-ci.org/FenrirUnbound/flipit)
[![Build Status](https://travis-ci.org/FenrirUnbound/flipit.png?branch=master)](https://travis-ci.org/FenrirUnbound/flipit)

# flipit

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

## 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](http://nodejs.org/api/fs.html#fs_class_fs_fswatcher) 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.
Document the API and example usage cases.
Document the API and example usage cases.
