Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
name: run demo
command: |
npm start | tee output.txt
grep "is true for this user" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1)
grep "is true for this context" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1)
27 changes: 14 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as LaunchDarkly from 'launchdarkly-node-server-sdk';
import * as LaunchDarkly from '@launchdarkly/node-server-sdk';

// Set sdkKey to your LaunchDarkly SDK key.
const sdkKey = "";

// Set featureFlagKey to the feature flag key you want to evaluate.
const featureFlagKey = "my-boolean-flag";

// Set up the user properties. This use should appear on your LaunchDarkly
// users dashboard soon after you run the demo.
const user = {
"name": "Sandy",
"key": "example-user-key"
// Set up the context properties. This use should appear on your LaunchDarkly
// contexts dashboard soon after you run the demo.
const context = {
"kind": "user",
"name": "Sandy",
"key": "example-context-key"
};

function showMessage(s: string) {
Expand All @@ -20,24 +21,24 @@ function showMessage(s: string) {

const client = LaunchDarkly.init(sdkKey);

client.once('ready', function() {
client.once('ready', function () {
showMessage("SDK successfully initialized!");
client.variation(featureFlagKey, user, false, function(err, showFeature) {
client.track("event-called", user);
client.variation(featureFlagKey, context, false, function (err, showFeature) {
client.track("event-called", context);
if (showFeature) {
// application code to show the feature
showMessage("Feature flag '" + featureFlagKey + "' is true for this user");
showMessage("Feature flag '" + featureFlagKey + "' is true for this context");
} else {
// the code to run if the feature is off
showMessage("Feature flag '" + featureFlagKey + "' is false for this user");
showMessage("Feature flag '" + featureFlagKey + "' is false for this context");
}

// Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
// events to LaunchDarkly before the program exits. If analytics events are not delivered,
// the user properties and flag usage statistics will not appear on your dashboard. In a
// the context properties and flag usage statistics will not appear on your dashboard. In a
// normal long-running application, the SDK would continue running and events would be
// delivered automatically in the background.
client.flush(function() {
client.flush(function () {
client.close();
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"typescript": "2.4.1"
},
"dependencies": {
"launchdarkly-node-server-sdk": "5.8.1"
"@launchdarkly/node-server-sdk": ">= 8.0.0"
}
}