NodeJS Client

Even though is still in closed alpha you can use our Node client right now with any other feature flag service. When comes out of alpha we will update this documentation.

The NodeJS client is compatible with Node 6.11.*.

The client has the following attributes:

View featureflagclient-node on npm.

Getting started

Install the client into your application via npm:

  npm install featureflagclient-node --save
Now require in the client and instantiate it. You need to pass the URL of your feature flag.

  const Featureflagclient = require( "featureflagclient-node" );
  const featureflagclient = new Featureflagclient( "" );

As this requires a HTTP request you will need to call getSourceFile before the client is ready:

  featureflagclient.getSourceFile().then( () => {
    // start coding
  }).catch( console.log );

Basic usage

You can interogate the client for flag values in two ways.

You can get a flag value:

  featureflagclientclient.get( "newFeature" );

This can be used as a condition in if statements.

We don't recommend doing that however, as littering your code with if statements makes your code more complex and is ugly.

We recommend that you use the pattern instead. Here's an example:

  featureflagclient.when( "newFeature" )
    .is( true, () => {
      // do the new stuff
    .else( () => {
      // do default stuff

Overriding values for you to test features

You may want to override values in the feature flag. This is useful when you need to test a feature by enabling it just for yourself and not all of your users.

The constructor takes an optional 2nd parameter, this is an object literal of override values. Here's an example that allows you to override a feature flag value using a parameter passed to an ExpressJS app:

  const featureflagclient = 
    new Featureflagclient(
        "falseBoolean": req.param( "falseBooleanOverride" ) || null

API reference


  new FeatureFlagClient( sourceFile, overrideValues );

Instantiates a new FeatureFlagClient object.





    .then( /* ... */ )
    .catch( /* ... */ );

Asynchronously fetches the feature flag file. If the flag is found the returned Promise resolves. If the request 404s or is not JSON then the Promise rejects.

Returns: Promise


get( featureName )

  get( "myNewFeature" );

Returns a feature value from the feature flag.

Returns: String.


when( featureName )

  when( "myNewFeature" )

Chaining function used with the is and else methods to access flag values in an expressive style. Returns self.

Returns: self.


is( flagValueToMatch, callback )

  is( true, () => {
    /* ... */

Chaining function used with the when and else methods to access flag values in an expressive style. Returns self.

Returns: self.


else( callback )

  else( () => {
    /* ... */

Pass in a callback to perform if none of the chained is method calls match the flag value.

Returns: nothing.