• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
No results for ""


Cloudflare Edge SDK

Read time: 1 minute
Last edited: Dec 13, 2021


This reference guide documents all of the methods available in the Cloudflare Edge SDK, which is a wrapper around the LaunchDarkly Node.js SDK, and explains in detail how these methods work. LaunchDarkly's SDKs are open source. To learn more, read Cloudflare Edge SDK repository on GitHub. The online API docs contain the programmatic definitions of every type and method. Additionally you can clone and run sample applications using this SDK with our sample application.

This SDK requires LaunchDarkly's Cloudflare integration

Configure the Cloudflare integration to use this SDK successfully. To learn more, read Cloudflare.

Getting started

To install and configure the Cloudflare Edge SDK in an existing project:

  1. Install the LaunchDarkly Cloudflare Edge SDK:
npm install launchdarkly-cloudflare-edge-sdk
  1. Configure Wrangler to use webpack to bundle your worker:
type = "webpack"
webpack_config = "webpack.config.js"
  1. Configure webpack:
module.exports = {
entry: './index.js',
target: 'webworker',
node: {
fs: 'empty',
tls: 'empty',
net: 'empty',
  1. Initialize the client with the Cloudflare KV namespace and LaunchDarkly client-side ID in your Worker:
const { init } = require('launchdarkly-cloudflare-edge-sdk');
let ldClient;
addEventListener('fetch', event => {
async function handleRequest(event) {
// client only needs to be initialized once, but may serve many requests
if (!ldClient) {
ldClient = init(MY_KV, 'YOUR_CLIENT_SIDE_ID');
await ldClient.waitForInitialization();
// ldClient may now be used for flag evaluation

You can now evaluate individual flags or fetch all flags from the SDK.

Supported features

This SDK supports the following features: