Registry / devops / flagsmith-cli

flagsmith-cli

JSON →
library0.2.3jsnpmunverified

The `flagsmith-cli` is a command-line interface tool designed to fetch feature flags and environment configurations from the Flagsmith API. Its primary use case is to generate a local JSON file, typically `flagsmith.json`, which can then be baked into an application as default flag state. This enables defensive coding practices, provides offline support, and facilitates CI/CD integration for feature flag management. The current stable version is `0.2.3`. Releases occur on an as-needed basis, focusing on bug fixes, dependency updates, and minor feature additions. The CLI is built on Oclif and ships with TypeScript types, targeting Node.js environments `>=12.0.0`. It serves as a crucial component for applications leveraging Flagsmith in scenarios requiring static flag data.

npm install flagsmith-cli
INSTALL
IMPORT
SIG · FLAGSMITH-CLI
F
flagsmith-cli
devopsjavascriptv0.2.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flagsmith
npx flagsmith get
import { flagsmith } from 'flagsmith-cli'
This package is a command-line interface tool; its primary interaction is via terminal commands, not JavaScript imports. `npx` is recommended for running local installations of the CLI.
FlagsmithState
import state from './flagsmith.json'
const state = require('./flagsmith.json')
The CLI generates a JSON file. This is how you import its contents into a JavaScript/TypeScript application, assuming your build setup supports JSON imports.
flagsmith
import flagsmith from 'flagsmith'
import { Flagsmith } from 'flagsmith'
This refers to the separate `flagsmith` client SDK package, which consumes the output of `flagsmith-cli`. You must install `flagsmith` separately if you intend to use it in your application.

Demonstrates installing the CLI, fetching flags into a `flagsmith.json` file, and then importing and initializing the Flagsmith client with these default flags for application use.

// 1. Install the CLI as a dev dependency // npm install flagsmith-cli --save-dev // 2. In your CI/CD or package.json "postinstall" script, // set the environment key and run the CLI to fetch flags. // (Replace 'YOUR_FLAGSMITH_ENVIRONMENT_KEY' with your actual key or use process.env) // Example using a shell command (e.g., in a CI script or `npm run get-flags`): // export FLAGSMITH_ENVIRONMENT="${process.env.FLAGSMITH_ENVIRONMENT_KEY ?? 'YOUR_FLAGSMITH_ENVIRONMENT_KEY'}" // npx flagsmith get --output ./src/flagsmith.json --pretty // 3. In your application code (e.g., src/main.ts or src/App.tsx): import flagsmith from 'flagsmith'; // Flagsmith client SDK (install separately: npm install flagsmith) import state from './flagsmith.json'; // The JSON file generated by flagsmith-cli async function initializeFlagsmith() { await flagsmith.init({ state, // Initial state fetched by the CLI environmentID: state.environmentID, // Extracted from the generated JSON // If you need the SDK to fetch live flags later, ensure API URL is correct: // apiUrl: 'https://edge.api.flagsmith.com/api/v1/', // Default Flagsmith API }); console.log('Flagsmith initialized with default state.'); // Example: Check a feature flag const myFeatureEnabled = flagsmith.hasFeature('example_feature_name'); console.log(`Is 'example_feature_name' enabled? ${myFeatureEnabled}`); // Get a flag value const welcomeMessage = flagsmith.getValue('welcome_message'); console.log(`Welcome message: ${welcomeMessage}`); } initializeFlagsmith();
flagsmith --version
Debug
Known issues
gotchaThe Flagsmith environment key is mandatory. It must either be provided via the `FLAGSMITH_ENVIRONMENT` environment variable or passed directly as an argument to the `flagsmith get` command.
fix
Ensure `FLAGSMITH_ENVIRONMENT` is set in your shell/CI environment, or use `flagsmith get YOUR_ENVIRONMENT_KEY`.
affects: >=0.1.0
gotchaWhen fetching flags for a specific identity using the `--trait` flag, you must also provide the `--identity` flag. Traits cannot be fetched in isolation.
fix
Include `-i <value>` or `--identity=<value>` when using any `-t <trait_key>=<trait_value>` flag.
affects: >=0.1.2
gotchaThe CLI defaults to `https://edge.api.flagsmith.com/api/v1/` for the API URL. If you are self-hosting Flagsmith or using a different region, you must specify the correct API URL.
fix
Use the `-a <value>` or `--api=<value>` flag to specify your custom Flagsmith API endpoint, e.g., `--api https://your.custom.flagsmith.com/api/v1/`.
affects: >=0.1.0
gotchaThe default output file is `./flagsmith.json`. If this file path is not suitable for your project structure, ensure you specify a different output.
fix
Use the `-o <value>` or `--output=<value>` flag to set the desired output file path, e.g., `--output ./src/flagsmith.ts`.
affects: >=0.1.0
Errors
Common errors & fixes
Missing required flag: --identity when using --trait
Attempting to fetch flags with traits without specifying an identity.
fix
Add the `-i <identity_value>` or `--identity=<identity_value>` flag when using `-t <trait_key>=<trait_value>`.
Error: Cannot find module './flagsmith.json'
The generated `flagsmith.json` file is not found at the specified import path, or your module resolver is not configured to handle JSON imports.
fix
Verify the `--output` path used during CLI execution matches your import path. Ensure your build tool (e.g., webpack, esbuild, TypeScript) is configured to handle JSON file imports.
Error: No environment key provided. Please set FLAGSMITH_ENVIRONMENT or pass it as an argument.
The Flagsmith environment key was neither provided as an argument to the `get` command nor set in the `FLAGSMITH_ENVIRONMENT` environment variable.
fix
Set the `FLAGSMITH_ENVIRONMENT` environment variable (e.g., `export FLAGSMITH_ENVIRONMENT='your_key'`) or pass the key directly as an argument: `flagsmith get your_key`.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources