NodeJS Overview

The client has the following attributes:

View featureflagtech-node on npm.

Step 1: Install Client

Install the client into your application via npm:


  npm install featureflagtech-node --save
      

Step 2: Import package

Now require in the client and instantiate it.


  const FeatureFlagTechClient = require( "featureflagtech-node" );  
      

Step 3: Create the featureflag.tech client with your API Key

You also need to use your API key...

 
  const f2t = new FeatureFlagTechClient({
    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();
      

Step 4: Get your flag value

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

Technique 1

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
  }  
      

Technique 2

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
    });
      

More Details

Need more information? See more techniques below.