Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
launchdarkly-js-client-sdk
Advanced tools
The launchdarkly-js-client-sdk is a JavaScript SDK for LaunchDarkly, a feature management platform that allows developers to control the release of features to users. This SDK enables you to manage feature flags, perform A/B testing, and roll out new features gradually.
Initialize the client
This code initializes the LaunchDarkly client with your environment key and a user object. The client is ready to be used once the 'ready' event is fired.
const LDClient = require('launchdarkly-js-client-sdk');
const client = LDClient.initialize('YOUR_ENVIRONMENT_KEY', { key: 'user_key' });
client.on('ready', () => {
console.log('LaunchDarkly client is ready');
});
Evaluate feature flags
This code evaluates a feature flag and returns its value. If the feature flag is enabled, it will log 'Feature is enabled'; otherwise, it will log 'Feature is disabled'.
client.on('ready', () => {
const showFeature = client.variation('your-feature-flag-key', false);
if (showFeature) {
console.log('Feature is enabled');
} else {
console.log('Feature is disabled');
}
});
Track custom events
This code tracks a custom event with a specified key and optional data. This can be useful for analytics and monitoring user interactions.
client.track('custom-event-key', { customData: 'value' });
Identify users
This code identifies a new user with a unique key and optional attributes. This is useful for targeting specific users with feature flags.
client.identify({ key: 'new_user_key', name: 'New User' }).then(() => {
console.log('User identified');
});
Unleash is an open-source feature management solution. The unleash-client package provides similar functionality to LaunchDarkly, allowing you to manage feature flags and control feature rollouts. However, Unleash is self-hosted, which means you need to manage the infrastructure yourself.
ConfigCat is a feature flag and configuration management service. The configcat-js package allows you to manage feature flags and configurations in your JavaScript applications. ConfigCat offers a hosted solution with a user-friendly interface, similar to LaunchDarkly.
Flagsmith is an open-source feature flag and remote config service. The flagsmith package provides similar functionality to LaunchDarkly, including feature flag management and user targeting. Flagsmith can be used as a hosted service or self-hosted, offering flexibility in deployment.
LaunchDarkly is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!
Refer to the SDK documentation for instructions on getting started with using the SDK.
Note: If you are using JavaScript in a non-browser environment, please see our server-side Node.js SDK, client-side Node.js SDK, and Electron SDK.
Please note that the JavaScript SDK has two special requirements in terms of your LaunchDarkly environment. First, in terms of the credentials for your environment that appear on your Account Settings dashboard, the JavaScript SDK uses the "Client-side ID"-- not the "SDK key" or the "Mobile key". Second, for any feature flag that you will be using in JavaScript code, you must check the "Make this flag available to client-side SDKs" box on that flag's Settings page.
The SDK does not require any particular JavaScript framework. However, if you are using React, there is an add-on to simplify use of the SDK. See react-client-sdk
.
The LaunchDarkly SDK can be used in all major browsers. However, web browsers vary widely in their support of specific features and standards. Three features that are used by the LaunchDarkly SDK that may not be available on every browser are Promise
, EventSource
, and document.querySelectorAll()
. For more information on whether you may need to use a polyfill to ensure compatibility, and how to do so, see "JS SDK requirements and polyfills".
By default, the SDK sends log output to the browser console. There are four logging levels: debug
, info
, warn
, and error
; by default, debug
and info
messages are hidden. See LDOptions.logger
and basicLogger
for more details.
Read our documentation for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the complete reference guide for this SDK. Additionally, the authoritative full description of all properties, types, and methods is the online TypeScript documentation. If you are not using TypeScript, then the types are only for your information and are not enforced, although the properties and methods are still the same as described in the documentation.
For examples of using the SDK in a simple JavaScript application, see hello-js
and hello-bootstrap
.
We run integration tests for all our SDKs using a centralized test harness. This approach gives us the ability to test for consistency across SDKs, as well as test networking behavior in a long-running application. These tests cover each method in the SDK, and verify that event sending, flag evaluation, stream reconnection, and other aspects of the SDK all behave correctly.
We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this SDK.
FAQs
LaunchDarkly SDK for JavaScript
We found that launchdarkly-js-client-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.