TypeScript icon, indicating that this package has built-in type declarations

2.1.3 • Public • Published


This is a node Feature Flag (Feature Toggle) module with common data/cache providers like json, mongodb, mysql, redis and others.

If you need more flexibility in your apps, like enable/disable features in production without change environments to deploy manualy or rerun the pipeline, this module is pretty good for you and your team.

It's not only used to turn on or turn off features or test A/B, you can use it to config your app in realtime, getting values from anywere (file, memory, databases, cache, api, realy anywere) to inject in your business logic to change it when you want.

Why should I use this one instead of create my own or use another?

  • Because it's easy to use, small size and you don't need to spend more time to code again.

  • Moreover, you can implement your own provider, just extending or implementing some provider or interface.

  • With this module, you can using your own infrastructure, like local or cloud databases, very important when your product or company is not so flexibility to explore other services.


Using npm:

npm install underflag

Using yarn:

yarn add underflag

How to use

Import the underflag and prepare to load data from some provider

Using implicit json data provider

import { Underflag } from "underflag";

const data = { test_a: true };
const underflag = new Underflag({ dataProvider: data });

if (await underflag.isOn("test_a")) {
    // ...

Using explicit json data provider

import { Underflag, JsonDataProvider } from "underflag";

const dataProvider = new JsonDataProvider({ "test_a": true });
const underflag = new Underflag({ dataProvider });

Others providers

Provider Package Use
HTTP https://www.npmjs.com/package/underflag-http Server or Client
MongoDB https://www.npmjs.com/package/underflag-mongodb Server
Mongoose https://www.npmjs.com/package/underflag-mongoose Server
Redis https://www.npmjs.com/package/underflag-redis Server
Memcached https://www.npmjs.com/package/underflag-memcached Server
MySQL https://www.npmjs.com/package/underflag-mysql Server
PostgreSQL https://www.npmjs.com/package/underflag-postgresql Server
DynamoDB https://www.npmjs.com/package/underflag-dynamodb Server
Firebase Remote Config - Admin https://www.npmjs.com/package/underflag-firebase-admin Server

The possible flow using memory + cache + data providers


Using data provider with Memory provider

import { Underflag, MemoryProvider } from "underflag"; 

(async() => {
    // memory provider
    const memoryProvider = new MemoryProvider({ lifetime: 5 });

    const underflag = new Underflag({ dataProvider: data, memoryProvider });
    await underflag.isOn('test_a'); // get from data provider and load memory
    await underflag.isOn('test_a'); // get from memory provider
    // after 5seg
    await underflag.isOn('test_a'); // get from data provider and load memory again

If you prefer, you can load all features from data provider to memory.

await underflag.loadMemory();
await underflag.isOn("test_a"); // from memory
await underflag.flushMemory(); // reset memory

Check the feature status:

const isOn = await underflag.isOn("test_a"); // return true or false

Get a feature:

const test_a = await underflag.getFeature("test_a");
console.log(test_a); // return undefined or feature object

Get a list of features:

const [test_a, test_b] = await underflag.getFeatures(["test_a", "test_b"]);
console.log("test_a", test_a);
console.log("test_b", test_b);

Get a feature flag:

const test_a = await underflag.getFlag("test_a");

Get a list of features:

const [test_a, test_b] = await underflag.getFlags(["test_a", "test_b"]);

Using your own data, cache or memory provider implementation

Just create your own class than implements IDataProvider, ICacheProvider or IMemoryProvider and pass to Underflag.

Feel free to contribute

  • If you find a bug or have a good idea, share with us.

  • And if you create a new module to data or cache provider, let us know to add here to help community.




npm i underflag

DownloadsWeekly Downloads






Unpacked Size

39.2 kB

Total Files


Last publish


  • diego.souza