In the docs, we are directed to create a client via const ld_client = LaunchDarkly.init('SOME_KEY');
Then in our server's request handler, we are directed to this code:
ld_client.once('ready', function() {
ld_client.variation("your.flag.key", {"key" : "user@test.com"}, false, function(err, show_feature) {
if (show_feature) {
# application code to show the feature
} else {
# the code to run if the feature is off
}
});
});
However, our Node app would work the first time a request came through, but time out on the second request. Why? Because our app was waiting for the 'ready' event, and it never came. So, we went with the following, based on what we found in the source code:
ld_client.waitForInitialization().then(() => {
ld_client.variation("your.flag.key", {"key" : "user@test.com"}, false, function(err, show_feature) {
if (show_feature) {
# application code to show the feature
} else {
# the code to run if the feature is off
}
});
}).then(console.log);
and now our node server can handle requests again, and we can update our LaunchDarkly settings and see the variations.
My only issue to please update the documentation. Thank you!