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 LaunchDarkly SDK for the Electron desktop application framework, and links to reference information on all of the supported features. This is a variant of the client-side JavaScript SDK with additional functionality for Electron.LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | Electron SDK |
| GitHub repository | electron-client-sdk |
| Sample application | Electron |
| Published module | npm |
Why use this instead of the Node.js SDK?
Because Electron is based on Node.js, it is possible to run the LaunchDarkly server-side Node.js SDK in it. However, we strongly discourage this because the server-side Node.js SDK is not meant for applications that are distributed to users. There are several reasons why this distinction matters:- The server-side SDKs include an SDK key that can download the entire definition, including rollout rules and individual user targets, of all of your feature flags. If you embed this SDK key in an application, any user who looks inside the application can then access all of your feature flag definitions, which may include sensitive data such as other users’ email addresses. The client-side and mobile SDKs use different credentials that do not allow this.
- The server-side SDKs download your entire flag data using this key, because they have to be able to evaluate flags quickly for any user. This can be a large amount of data. The client-side and mobile SDKs, which normally evaluate flags for just one user at a time, use a much more efficient protocol where they request only the active variation for each flag for that specific user.
Server-side Node.js SDK compatibility
For developers who were using the server-side Node.js in Electron before the Electron SDK was available, there are differences between the APIs that can be inconvenient. For instance, in the server-side Node.js SDK,variation() is an asynchronous call that takes a callback, whereas in the client-side SDKs it is synchronous.
To make this transition easier, the LaunchDarkly Electron SDK provides an optional wrapper that emulates the Node.js SDK. When you create the main-process client, after you call initializeInMain, pass the client object to createNodeSdkAdapter. The resulting object uses the Node-style API.
Here’s how to create the wrapper:
client.variation(flagKey, user, defaultValue) it is really calling client.identify(user) first, obtaining flag values for that user, and then evaluating the flag. This performs poorly if you attempt to evaluate flags for a variety of different users in rapid succession.
Get started
After you complete the Get started process, follow these instructions to start using the LaunchDarkly SDK in your Electron code:Install the SDK
You can install the SDK into your Electron project usingnpm:
Initialize the client
Every Electron application consists of a main process, which is similar to a Node.js application, and some number of renderer processes, each of which is a Chromium web browser with its own window. These processes have their own independent JavaScript engines and data spaces, although there are ways to communicate between them. We designed the LaunchDarkly Electron SDK to use LaunchDarkly feature flags from within any of these processes. In the normal use case, there is an SDK client running in the main process and the renderer processes can then create client instances that are in effect mirrors of the main one. To set up the main process client, you need the client-side ID for your LaunchDarkly environment, an object containing user properties, and optional configuration properties. You can change the user later if needed. The client-side ID authorizes your application to connect to a particular environment within LaunchDarkly. To initialize the client:LDOptions.
To create a client object that uses the same feature flag data in a renderer process, use this:
ready event or waitForInitialization():
variation will return the fallback value.
Evaluate a flag
After you create the client, you can use it to check which variation a particular user will receive for a feature flag. Here’s how:Shut down the client
Shut down the client when your application terminates. To learn more, read Shutting down.Troubleshooting
If your application logs show the errorLaunchDarklyFlagFetchError: network error, it may indicate a problem with network connectivity between your SDK and LaunchDarkly.
For steps to resolve this issue, read the LaunchDarkly Knowledge Base article Error “LaunchDarklyFlagFetchError: network error”.
Supported features
This SDK supports the following features:- Aliasing users
- Anonymous contexts and users
- Bootstrapping
- Configuration
- Context configuration
- Evaluating flags
- Flag evaluation reasons
- Getting all flags
- Identifying and changing contexts
- Logging configuration
- Monitoring SDK status
- Private attributes
- Relay Proxy configuration, using proxy mode
- Secure mode
- Sending custom events
- Service endpoint configuration
- Shutting down
- Subscribing to flag changes