NodeJS API Reference

The client has the following attributes:

View featureflagtech-node on npm.

Getting started

Install the client into your application via npm:


  npm install featureflagtech-node --save
      

Now require in the client and instantiate it. You need to pass your featureflag.tech credentials...


  const FeatureFlagTechClient = require( "featureflagtech-node" );
  
  const f2t = new FeatureFlagTechClient({
    userId: "__YOUR_USER_ID__", 
    projectName: "example.com",
    environment: "live",
    apiKey: "__YOUR_ENVIRONMENT_API_KEY__"
  });
      

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


  await f2t.getFlag();
      

Basic usage

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

You can get a flag value:


  f2t.get( "newFeature" );
      

This can be used as a condition in if statements.


  if ( f2t.get( "newFeature" ) ) {
    // do the new stuff
  }  
      

Or you can use the library's when.is pattern instead. Here's an example:


  f2t.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 f2t = 
    new FeatureFlagTechClient(
      {
        userId: "__YOUR_USER_ID__",
        projectName: "example.com",
        environment: "live",
        apiKey: "__YOUR_ENVIRONMENT_API_KEY__"
      },
      {
        "falseBoolean": req.param( "falseBooleanOverride" ) || null
      }
    );
      

API reference

Constructor


  new FeatureFlagTechClient( credentials, overrideValues );
      

Instantiates a new FeatureFlagClient object.

Arguments:

Properties:

Methods

getFile()


  await getFlag();
      

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

Arguments:

get( featureName )


  get( "myNewFeature" );
      

Returns a feature value from the feature flag.

Returns: String.

Arguments:

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.

Arguments:

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.

Arguments:

else( callback )


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

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

Returns: nothing.

Arguments: