This guide covers how developers install and configure the packaged SDK, how SDK keys are generated/managed, and how to deploy the feature flag system (Backend and Frontend) so other developers/users can access it from their own machines.
Once you publish the package to npmjs.com, anyone can install it in their project:
npm install feature-flag-client-sdkHere is how developers initialize and use it in a JavaScript/TypeScript application:
import { FeatureFlagClient } from 'feature-flag-client-sdk';
// 1. Initialize the client
const ffs = new FeatureFlagClient('sdk_prod_your_key_123', {
baseUrl: 'https://your-feature-flag-api.com', // Your deployed backend API
enableStream: true, // Receive instant real-time changes via Server-Sent Events (SSE)
});
// 2. Fetch flag definitions & connect stream
await ffs.initialize();
// 3. Define the current user context
const user = {
userId: 'user-id-54321',
email: 'client@company.com',
plan: 'premium',
country: 'US'
};
// 4. Perform instant, local evaluation (<1ms)
const decision = ffs.evaluate('new-ui-theme', user, 'default-light');
console.log(`Serve theme: ${decision.value} (Reason: ${decision.reason})`);- Open your Feature Flag Dashboard.
- Select or create a Project.
- Under the Environments settings, you will see your environments (e.g.,
Development,Staging,Production). - Each environment has a unique, automatically generated SDK Key (e.g.,
sdk_dev_default_key_123). Copy this key to initialize the client.
- Bootstrap: The SDK sends a
GET /api/v1/sdk/bootstrap?envKey=YOUR_SDK_KEYrequest to your backend to pull all flag definitions for that environment. - Stream: The SDK opens a persistent
GET /api/v1/sdk/stream?envKey=YOUR_SDK_KEYSSE (Server-Sent Events) connection. The backend uses this to broadcast a message when a flag is edited. - Local Engine: When
ffs.evaluate()is called, no API call is made. The SDK evaluates the rules locally using the cached definitions, making evaluations instant. - Analytics: The SDK batches metrics and sends them via
POST /api/v1/sdk/evaluationsevery few seconds to feed the dashboard charts.
Since everything currently runs on localhost, you need to deploy them to public servers so developers can use your SDK from their laptops.
If you want to demo it instantly from your laptop without deploying code to the cloud:
- Download Ngrok.
- Run ngrok to expose your backend port:
ngrok http 3001
- Ngrok will give you a public URL (e.g.,
https://a5b4-103.xxx.xxx.ngrok-free.app). - Pass this public URL as the
baseUrlin the SDK constructor.
To make it permanently available, deploy the dashboard, backend, and database.
- PostgreSQL (Database): Use a free managed database service like Supabase or Aiven.
- Obtain the connection string (
DATABASE_URL). - (Note: Redis is not required since the system runs on a single backend instance using the built-in memory event bus.)
- Hosting Platforms: Deploy to Render, Railway, or Fly.io (which all support Node.js/Docker deployments).
- Setup Environment Variables:
- Set
DB_TYPE=postgres - Set
CACHE_TYPE=memory - Set
DATABASE_URL=your-supabase-postgres-url - Set
JWT_SECRET=your-secure-secret-key - Set
PORT=3000(or whatever the host exposes)
- Set
- Hosting Platforms: Deploy to Vercel or Netlify.
- Configuration:
- Set the environment variable
VITE_API_URLto point to your deployed backend URL. - Run the build command (
npm run build) and point the publish directory todist/.
- Set the environment variable