Flipper-js
Flipper-js manage the feature flipping in your application
Inspired from the GEM Flipper Ruby GEM Flipper
Features
- CLI management
- In code management
- UI management
Installation
npm i flipper-js
Configuration
The configuration is on a json file (features.json) that you have to create on your application :
{
"features": {
"feature1": true,
"feature2": false
},
"storage": {
"type": "local"
}
}
Storage types are
- local : use this file (read and write) to manage the feature flipping.
- redis : use the redis (you provide) to store the feature.
Env vars
- FLIPPER_API_KEY : the api key used to authenticate interaction with the flipper UI
- FLIPPER_REDIS_URL : The redis connection url
CLI
The feature flipping could be managed by a CLI
npx flipper-js --help
you have to set the env var FLIPPER_REDIS_URL if you are using the redis storage type.
export FLIPPER_REDIS_URL=redis://user:passxord@redis:6379
Options
-V, --version output the version number
-h, --help display help for command
Commands
- list : List all features and their statuses
- enable "feature" : Enable a feature
- disable "feature" : Disable a feature
- add "feature" : Add a new feature (enabled by default)
In code management
Initialisation
import path from 'path'
import { Flipper } from 'flipper-js'
Flipper.init(path.join(__dirname, '../features.json'))
Usage
import { Flipper } from 'flipper-js'
await Flipper.isEnabled('feature1')
await Flipper.enable('feature1')
await Flipper.disable('feature1')
await Flipper.list()
UI management
UI management is using an express router
The router is exported and could be included in your app.
Example with Express
import { Flipper, User, FlipperRouter } from 'flipper-js'
Flipper.init()
app.use(FlipperRouter.of('express'))
User.addUser(process.env.FLIPPER_USER_LOGIN, process.env.FLIPPER_USER_PASSWORD)
Other router (Nest.js, Fastify) are coming
To access : launch https://yourserver.com/flipper-js
The connection is the login provided by the addUser method.
Inside the UI, you can simply enable or disabled features.