launchdarkly / node-server-sdk

LaunchDarkly Server-side SDK for Node
Other
79 stars 65 forks source link

Unable to get feature flag using variation method #154

Closed VarshaKamble159 closed 5 years ago

VarshaKamble159 commented 5 years ago

Hi,

I am trying to integrate node-server-sdk in my application. I am able to initialize Launch darkly with sdk-key. Also i am getting available flags using allFlagsState .

     ldClient = LaunchDarkly.init("sdk-key");
     ldClient.allFlagsState({}, function(err, flagsState) {
           //Here I am getting all available feature flags
            var flagStateProps = flagsState.toJSON()['$flagsState'];
            console.log("All available feature flags", flagStateProps);           
        });

When i am trying to check flag availability using variation method, i am always getting false as response, where this flag is available in allFlags. Following is the code for the same.

  ldClient.variation("feature_flag", {}, false, function(err, show_feature) {
      if (show_feature) {
         console.log("TRUE");
     } else {
      // Always returning false
           console.log("FALSE");
       }
 });

Please suggest for the same.

installed npm LaunchDarkly version : "launchdarkly-node-server-sdk": "5.8.2"

NOTE: I am able to get feature flag in JAVA launchdarkly sdk with same sdk-key.

ldClient = new LDClient(sdk-key, {});  
LDUser ldUser = null;
boolean boolVariation = ldClient.boolVariation(feature, ldUser, false); // It returns true for same feature flag.
bwoskow-ld commented 5 years ago

Hi @VarshaKamble159 ,

I see that you've already closed your issue. As a result I assume that you've identified and resolved your problem.

While I'm here, I want to point you to our SDK documentation which has information about how to use the variation method as well as other SDK features.

This particular issue is actually a support request and not a SDK bug report. Don't hesitate to reach out to support@launchdarkly.com for additional help adopting the Node Server SDK in your application.

Cheers, Ben

eli-darkly commented 5 years ago

For the record, briefly, the two problems I see in this code are 1. you don't have a valid user object (users should have at least a key) and 2. var flagStateProps = flagsState.toJSON()['$flagsState'] does not give you the flag values, it gives you some metadata containing objects which might look like a true flag value to you because objects are always "truthy"; what you want is just var flagStateProps = flagsState.allValues().

VarshaKamble159 commented 5 years ago

Hi @eli-darkly and @bwoskow-ld ,

Thank you so much guys for your replies. Yes, i identified the issue in my code and was able to solve it. I appreciate your response.

Will surely reach out to you guys in case of any further help.

Thanks, Varsha