| title | Apply Code Changes |
|---|---|
| description | Install the SDK dependency and add initialization code to the application entrypoint |
Now execute the integration plan. Install the SDK and add the minimal code needed to initialize it.
Run the install command from the SDK Recipes using the project's package manager.
Examples:
# Node.js (npm)
npm install @launchdarkly/node-server-sdk --save
# Python (pip)
pip install launchdarkly-server-sdk
# Go
go get github.com/launchdarkly/go-server-sdk/v7
# Ruby
bundle add launchdarkly-server-sdk
# .NET
dotnet add package LaunchDarkly.ServerSdkAfter installation, verify the dependency appears in the lock file or dependency manifest.
Never hardcode SDK keys in source code.
Add the appropriate environment variable:
| SDK Type | Variable Name | Where to Get It |
|---|---|---|
| Server-side | LAUNCHDARKLY_SDK_KEY |
LaunchDarkly > Project settings > Environments > SDK key |
| Client-side | LAUNCHDARKLY_CLIENT_SIDE_ID |
LaunchDarkly > Project settings > Environments > Client-side ID |
| Mobile | LAUNCHDARKLY_MOBILE_KEY |
LaunchDarkly > Project settings > Environments > Mobile key |
Add to the project's environment configuration:
- If
.envexists, add the variable there - If
.env.exampleor.env.sampleexists, add a placeholder entry - If the project uses a config module, add it there following existing patterns
# .env
LAUNCHDARKLY_SDK_KEY=your-sdk-key-hereTell the user they need to replace the placeholder with their actual key.
Add the import and initialization code to the application entrypoint. Place initialization early in the startup sequence, before any code that might need feature flags.
- Import at the top of the file with other imports
- Initialize early in the application lifecycle
- Wait for initialization before evaluating flags (most SDKs support this)
- Handle errors — log failures but don't crash the application
- Match existing code style — use the same patterns (async/await, callbacks, error handling) as the rest of the codebase
// Node.js example
const LaunchDarkly = require('@launchdarkly/node-server-sdk');
const ldClient = LaunchDarkly.init(process.env.LAUNCHDARKLY_SDK_KEY);
// Wait for initialization before serving requests
await ldClient.waitForInitialization();
console.log('LaunchDarkly SDK initialized successfully');# Python example
import ldclient
from ldclient.config import Config
ldclient.set_config(Config(os.environ['LAUNCHDARKLY_SDK_KEY']))
client = ldclient.get()
if client.is_initialized():
print('LaunchDarkly SDK initialized successfully')// Go example
import ld "github.com/launchdarkly/go-server-sdk/v7"
ldClient, err := ld.MakeClient(os.Getenv("LAUNCHDARKLY_SDK_KEY"), 5*time.Second)
if err != nil {
log.Printf("LaunchDarkly SDK failed to initialize: %v", err)
}// React example
import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk';
const LDProvider = await asyncWithLDProvider({
clientSideID: process.env.REACT_APP_LAUNCHDARKLY_CLIENT_SIDE_ID,
context: {
kind: 'user',
key: 'anonymous',
},
});
// Wrap your app with the provider
root.render(
<LDProvider>
<App />
</LDProvider>
);Refer to the SDK Recipes for language-specific import and init snippets.
After making changes:
- Run the project's build or compile step
- Run the linter if one is configured
- Fix any import errors or type issues
Do not proceed to the next step if the code doesn't compile.
[STATUS] Installing SDK dependency
[STATUS] Configuring SDK key
[STATUS] Adding initialization code
[STATUS] Verifying code compiles
Upon completion, continue with: Start the Application