LaunchDarkly CLI commands
Overview
This topic describes common commands and configuration options in the LaunchDarkly CLI.
The commands included here require you to authenticate yourself, either by logging in to LaunchDarkly or by setting or passing in an access token. To learn how, read Authentication.
View available commands
The majority of the LaunchDarkly CLI commands are resource commands. These commands provide direct access to LaunchDarkly APIs.
To view available commands:
Set input and output formats
For each LaunchDarkly CLI resource command, you can use command line arguments, or use your shell to provide an input file.
For example, here’s how to create a flag using data from the command line:
Here’s how to create the same flag using data from a file:
By default, resource commands return a simplified plaintext output. For example, the default output message for creating the new flag in the example above is Successfully created Example flag (example-flag)
.
To view the full JSON response from any resource command, use the --output json
flag. Optionally, pipe the result through jq
for improved formatting. Here’s how:
If you prefer a particular output format, you can use the config
command to set that preference:
Access SDK credentials
You can access the SDK credentials for a specific project and environment using the environments
resource. You need different SDK credentials depending on which SDK you’re working with. To learn more about SDK credentials, read Keys.
Here’s how:
Use ldcli
for local development
The LaunchDarkly CLI includes a dev-server
command that you can use to start a local server, retrieve flag values from a LaunchDarkly source environment, and update those flag values locally. This means you can test your code locally, without having to coordinate with other developers in your organization who are using the same LaunchDarkly source environment.
To learn more, use ldcli dev-server --help
or read our guides, Using the LaunchDarkly CLI for local testing and LaunchDarkly CLI dev-server reference.
Use ldcli
for uploading sourcemaps
The LaunchDarkly CLI includes a sourcemaps
command that you can use to upload JavaScript sourcemaps to LaunchDarkly. This means your sourcemaps are available when you access error monitoring in the LaunchDarkly UI. You must be using the Observability plugin with the JavaScript SDK to use the error monitoring feature.
Here’s how to upload your JavaScript sourcemap:
The sourcemaps upload
command uploads a local version of your sourcemap to LaunchDarkly. To use the command, you must have generated sourcemaps for your project. Exactly how to do this depends on your target environment and JavaScript configuration. Bundlers such as babel, webpack, esbuild, and rollup all provide different ways to enable sourcemap generation. Refer to the documentation for your specific bundler to generate production-ready sourcemaps.
The app-version
option takes a string that should match the version you include in the observability plugin options.
The path
option defaults to ./build
. The command uploads any .map
files in the directory specified here.
The basePath
option ensures that LaunchDarkly stores the sourcemaps at an appropriate location corresponding to your application’s deployment. For example, suppose your sourcemap file is in ./build/myApp
and that when you deploy your app, your code runs from ./dist/myApp
. You should provide --path ./build/myApp --basePath ./dist/myApp
.
The project
option is the LaunchDarkly project key.
If your sourcemap is inline, meaning it’s already shipped as part of your application, then you do not need to upload anything to LaunchDarkly.
To learn more, use ldcli sourcemaps --help
.
Find additional documentation
LaunchDarkly provides the following additional documentation:
- For information on how to get started with the LaunchDarkly CLI, read LaunchDarkly CLI.
- For details on how to use the LaunchDarkly CLI to perform local testing and development, read Using the LaunchDarkly CLI for local testing and LaunchDarkly CLI dev-server reference.
You can also use the ldcli [command] --help
command to view usage information for all commands for the LaunchDarkly CLI.
To view and contribute to the LaunchDarkly CLI source code, or to file issues for our team, visit the LaunchDarkly CLI GitHub repository.