Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This topic documents how to get started with the Cloudflare SDK, and links to reference information on all of the supported features.LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | Cloudflare SDK |
| GitHub repository | js-core/packages/sdk/cloudflare |
| Sample application | Example app |
| Published module | npm , jsr |
- The Cloudflare SDK gets all flags at the edge for a given context, and bootstraps them onto a cached payload
- The client-side SDK initializes the bootstrapped payload
- The client-side SDK evaluates the flags and sends events back to LaunchDarkly
Configure the Cloudflare integration to use this SDK successfully. To learn more, read Cloudflare.The Cloudflare integration is only available to customers on select plans. To learn more, read about our pricing. To upgrade your plan, contact Sales.
Get started
After you configure the Cloudflare integration process in an existing project, follow these instructions to start using the LaunchDarkly SDK in your Cloudflare Worker:Install the SDKFirst, install the Launch
Darkly SDK as a dependency in your application using your application’s dependency manager. Here’s how:wrangler.toml to allow the SDK to use node:events. Specify a build command in your wrangler.toml to use a bundler. Using a bundler to build your edge worker is recommended by Cloudflare.
Initialize the client
After you install and import the SDK, create an instance ofLDClient. Specify your client-side ID and Cloudflare KV namespace here. The client-side ID is only used to query the KV namespace, not to connect with LaunchDarkly servers.
Here’s how:
Evaluate a flag
Await thewaitForInitialization function after you initialize the client. When waitForInitialization is resolved the client can serve feature flags.
Using client, you can check which variation a particular context will receive for a given feature flag. In your Cloudflare Worker application, place the client.variation code so that it is invoked as needed.
Here is an example:
Example Worker
This is an example Cloudflare Worker application that initializes the ldClient and evaluates a feature flag for a context:Promises and async
All asynchronous SDK methods that return aPromise are compatible with then/catch or async/await. You can use either.
Shut down the client
If you send events, you must flush those events before your worker exits to ensure that they are sent back to LaunchDarkly. To learn more, read Flushing events. Shut down the client when your application terminates. To learn more, read Shutting down.Supported features
- Anonymous contexts and users
- Configuration, including
- Context configuration
- Evaluating flags
- Flag evaluation reasons
- Flushing events
- Getting all flags
- Logging configuration
- Migrations
- Secure mode
- Sending custom events
- Shutting down
Use in Cloudflare Workers only
This SDK is intended only for use in multi-user Cloudflare Workers only. Choose one of the other JavaScript-based SDKs for browser, server, or mobile environments. Client-side browser environments:- For React applications, read the React Web SDK reference.
- For Vue applications, read the Vue SDK reference.
- For all other client-side browser JavaScript applications, read the JavaScript SDK reference. Non-browser environments:
- For server-side Node applications, read the Node.js SDK reference (server-side).
- For client-side Node applications, read the Node.js SDK reference (client-side).
- For React Native mobile applications read the React Native SDK reference.
- For Electron desktop applications, read the Electron SDK reference. To learn more about LaunchDarkly’s different SDK types, read Choosing an SDK type.