# express-feature-flag

> Feature Flag system as a Express middleware

Latest version **0.2.0** (published 2014-12-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install express-feature-flag
pnpm add express-feature-flag
yarn add express-feature-flag
bun add express-feature-flag
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2014-12-07 |
| First published | 2014-10-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Young |
| Maintainers | aprilrd |
| Keywords | express, feature, feature-toggle, feature-flag |

## Links

- npm: https://www.npmjs.com/package/express-feature-flag
- Repository: https://github.com/aprilrd/express-feature-flag
- Issues: https://github.com/aprilrd/express-feature-flag/issues
- npm.io page: https://npm.io/package/express-feature-flag

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [higher-object](https://npm.io/package/higher-object.md) ^0.2.3

## Recent versions

- 0.2.0 (latest) — 2014-12-07
- 0.1.3 — 2014-10-30
- 0.1.2 — 2014-10-25
- 0.1.1 — 2014-10-25
- 0.1.0 — 2014-10-25

## README

# express-feature-flag

Feature Flag system as an [express.js]( https://github.com/visionmedia/express ) middleware.

## Installation

```
npm install express-feature-flag
```

## Usage

```javascript
app.use(require('express-feature-flag')({
  contextGenerator: function (req, callback) {
    callback(null, req.session); //do other queries if necessary
    return;
  },

  ruleGenerator: function (callback) {
    queryFeatureFlagDB(function (err, featureFlagRules) {
      if (err) {
        callback(err);
        return;
      }

      var rule, rules, _i, _len;

      rules = {};

      for (_i = 0, _len = featureFlagRules.length; _i < _len; _i++) {
        rule = featureFlagRules[_i];
        rules[rule.name] = parseRuleSpec(rule.rule);
      }

      callback(null, rules);
    })
  }
})); // returns a middleware function
```

###Middleware Options
####`contextGenerator` Function(req, callback) [_optional_]
An asynchronous function to generate `context` which will then be used as an argument to feature flag rules.

If not supplied, `context` will be `req`.

####`ruleGenerator` Function(callback) [_required_]
An asynchronous function to generate rules.

callback's first argument is `error` and second argument is `rules`. `rules` have to be an object whose names are the name of rules and values are functions that takes `context` and returns `boolean`.

`rules` Example:
```javascript
{
  htmlEmail: function (context) {
    if (context.type === 'admin') {
        return true;
    }
    return false;
  }
}
```
## ToDo
- Include basic rule spec

## Changelog

### v0.1.3
- Added stricter type checking to FeatureFlagCollection

### v0.1.0
- Initial release

## Contributors

- Young Kim <aprilrd8943@gmail.com>

## License
ISC License

---
_Source: https://npm.io/package/express-feature-flag · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
