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 server-side Node.js SDK. It also links to reference information for all of the features the server-side Node.js SDK supports.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 | Node.js server SDK |
| GitHub repository | node-server-sdk |
| Sample applications | Node.js (server-side) , Node.js (server-side), TypeScript , Node.js (server-side) with bootstrapping , OpenFeature Node.js (server-side) |
| Published module | npm |
Get started
After you complete the Getting Started process, follow these instructions to start using the LaunchDarkly SDK in your Node.js application.Install the SDK
First, install the LaunchDarkly SDK as a dependency in your application using your application’s dependency manager. We recommend making the LaunchDarkly observability plugin available as well. This plugin collects and sends observability data to LaunchDarkly, including metrics autogenerated from OpenTelemetry data. This means you can review error monitoring, logs, and traces from within the LaunchDarkly UI. They require the Node.js (server-side) SDK version 9.10 or later. Here’s how:The Node.js (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
Initialize the client
After you install and import the SDK, create a single, shared instance ofLDClient. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.
Here’s how:
LDOptions.
The client emits a ready event when you initialize it and it can serve feature flags.
Evaluate a context
Usingclient, you can check which variation a particular context will receive for a given feature flag. The ready event is only emitted once, when you first initialize the client. In a production application, place your client.variation code so that it is invoked as needed.
Here is an example:
Promises and async
All asynchronous SDK methods which accept a callback also return aPromise. This means that if your application uses promises to manage asynchronous operations, interacting with the SDK should be convenient. Because the async/await syntax is based on Promises, these methods also work with await.
Here is an example:
ready event:
allFlagsState and flush also return a Promise.
Shut down the client
Shut down the client when your application terminates. To learn more, read Shutting down. Unlike other LaunchDarkly SDKs, the Node.js (server-side) SDK does not automatically send pending analytics events to LaunchDarkly when it shuts down. To send analytics events, you first need to call flush.Supported features
This SDK supports the following features:- Anonymous contexts and users
- Big segments
- Bootstrapping
- Configuration, including
- Context configuration
- Data saving mode
- Evaluating flags
- Flag evaluation reasons
- Flushing events
- Getting all flags
- Hooks
- Identifying and changing contexts
- Logging configuration
- Migrations
- Observability
- Offline mode
- OpenTelemetry
- Private attributes
- Reading flags from a file
- Relay Proxy configuration
- Secure mode
- Sending custom events
- Service endpoint configuration
- Shutting down
- Storing data
- Subscribing to flag changes
- Test data sources
- Web proxy configuration