1- import * as LaunchDarkly from 'launchdarkly- node-server-sdk' ;
1+ import * as LaunchDarkly from '@ launchdarkly/ node-server-sdk' ;
22
33// Set sdkKey to your LaunchDarkly SDK key.
44const sdkKey = "" ;
55
66// Set featureFlagKey to the feature flag key you want to evaluate.
77const featureFlagKey = "my-boolean-flag" ;
88
9- // Set up the user properties. This use should appear on your LaunchDarkly
10- // users dashboard soon after you run the demo.
11- const user = {
12- "name" : "Sandy" ,
13- "key" : "example-user-key"
9+ // Set up the context properties. This use should appear on your LaunchDarkly
10+ // contexts dashboard soon after you run the demo.
11+ const context = {
12+ "kind" : "user" ,
13+ "name" : "Sandy" ,
14+ "key" : "example-context-key"
1415} ;
1516
1617function showMessage ( s : string ) {
@@ -20,24 +21,24 @@ function showMessage(s: string) {
2021
2122const client = LaunchDarkly . init ( sdkKey ) ;
2223
23- client . once ( 'ready' , function ( ) {
24+ client . once ( 'ready' , function ( ) {
2425 showMessage ( "SDK successfully initialized!" ) ;
25- client . variation ( featureFlagKey , user , false , function ( err , showFeature ) {
26- client . track ( "event-called" , user ) ;
26+ client . variation ( featureFlagKey , context , false , function ( err , showFeature ) {
27+ client . track ( "event-called" , context ) ;
2728 if ( showFeature ) {
2829 // application code to show the feature
29- showMessage ( "Feature flag '" + featureFlagKey + "' is true for this user " ) ;
30+ showMessage ( "Feature flag '" + featureFlagKey + "' is true for this context " ) ;
3031 } else {
3132 // the code to run if the feature is off
32- showMessage ( "Feature flag '" + featureFlagKey + "' is false for this user " ) ;
33+ showMessage ( "Feature flag '" + featureFlagKey + "' is false for this context " ) ;
3334 }
3435
3536 // Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
3637 // events to LaunchDarkly before the program exits. If analytics events are not delivered,
37- // the user properties and flag usage statistics will not appear on your dashboard. In a
38+ // the context properties and flag usage statistics will not appear on your dashboard. In a
3839 // normal long-running application, the SDK would continue running and events would be
3940 // delivered automatically in the background.
40- client . flush ( function ( ) {
41+ client . flush ( function ( ) {
4142 client . close ( ) ;
4243 } ) ;
4344 } ) ;
0 commit comments