Configuration
The SDK is designed to work optimally out of the box with minimal configuration. Only your API key is required.
Basic Configuration
import { Featsync } from '@featsync/sdk';
const featsync = new Featsync({ apiKey: 'fs_your_api_key',});That’s it! The SDK automatically:
- Caches flags for 5 minutes
- Persists to localStorage for offline support
- Prefetches all flags on initialization
- Uses a 5-second request timeout
Full Configuration
const featsync = new Featsync({ // Required: Your API key from the dashboard apiKey: 'fs_your_api_key',
// Optional: Environment to evaluate (default: 'production') environment: 'production',});Configuration Options
apiKey (required)
Your API key from the Featsync dashboard. Each environment has its own API key.
apiKey: 'fs_abc123...';environment
The environment to evaluate flags against. Defaults to 'production'.
environment: 'production'; // or 'staging', 'development'Built-in Defaults
The SDK uses optimized defaults that work well for most applications:
| Setting | Value | Description |
|---|---|---|
| Cache duration | 5 minutes | Flags are cached to minimize API calls |
| Request timeout | 5 seconds | Balanced timeout for reliability |
| Prefetch | Always enabled | Flags load immediately on initialization |
| Persistence | Always enabled | localStorage fallback for offline support |
These values are carefully chosen based on best practices and cannot be overridden.
Environment Variables
We recommend using environment variables for configuration:
const featsync = new Featsync({ apiKey: process.env.FEATSYNC_API_KEY, environment: process.env.NODE_ENV,});Next.js
FEATSYNC_API_KEY=fs_abc123...Vite
VITE_FEATSYNC_API_KEY=fs_abc123...const featsync = new Featsync({ apiKey: import.meta.env.VITE_FEATSYNC_API_KEY,});Singleton Pattern
Create a single SDK instance and reuse it throughout your application:
import { Featsync } from '@featsync/sdk';
export const featsync = new Featsync({ apiKey: process.env.FEATSYNC_API_KEY,});import { featsync } from './lib/featsync';
if (await featsync.isEnabled('my-flag')) { // ...}Next Steps
- Learn basic usage patterns
- Set up React integration with hooks