What is @launchdarkly/js-server-sdk-common?
@launchdarkly/js-server-sdk-common is a common library for LaunchDarkly's JavaScript server-side SDKs. It provides core functionality for feature flag evaluation, user targeting, and other feature management capabilities.
What are @launchdarkly/js-server-sdk-common's main functionalities?
Feature Flag Evaluation
This feature allows you to evaluate feature flags for a given user. The code sample demonstrates how to initialize the client, wait for it to be ready, and then evaluate a feature flag for a specific user.
const { LDClient } = require('@launchdarkly/js-server-sdk-common');
const client = new LDClient('YOUR_SDK_KEY');
client.on('ready', () => {
const user = { key: 'user123' };
const showFeature = client.variation('your-feature-flag-key', user, false);
console.log(`Feature flag value: ${showFeature}`);
});
User Targeting
This feature allows you to target specific users based on their attributes. The code sample shows how to include user attributes like email in the evaluation process.
const { LDClient } = require('@launchdarkly/js-server-sdk-common');
const client = new LDClient('YOUR_SDK_KEY');
client.on('ready', () => {
const user = { key: 'user123', email: 'user@example.com' };
const showFeature = client.variation('your-feature-flag-key', user, false);
console.log(`Feature flag value for user: ${showFeature}`);
});
Event Tracking
This feature allows you to track custom events for analytics and reporting. The code sample demonstrates how to track a custom event for a specific user.
const { LDClient } = require('@launchdarkly/js-server-sdk-common');
const client = new LDClient('YOUR_SDK_KEY');
client.on('ready', () => {
const user = { key: 'user123' };
client.track('custom-event', user, { key: 'value' });
console.log('Custom event tracked');
});
Other packages similar to @launchdarkly/js-server-sdk-common
flagr
Flagr is an open-source feature flagging and A/B testing tool. The flagr package provides feature flag evaluation and user targeting functionalities. It is comparable to @launchdarkly/js-server-sdk-common but is open-source and can be customized to fit specific needs.
LaunchDarkly SDK JavaScript Common Server Code
This project contains Typescript classes and interfaces that are applicable to server-side SDKs.
Contributing
See Contributing.
Verifying SDK build provenance with the SLSA framework
LaunchDarkly uses the SLSA framework (Supply-chain Levels for Software Artifacts) to help developers make their supply chain more secure by ensuring the authenticity and build integrity of our published SDK packages. To learn more, see the provenance guide.
About LaunchDarkly
- LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
- Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
- Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
- Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
- Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
- LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
- Explore LaunchDarkly