{"id":18373,"library":"featurehub-javascript-client-sdk","title":"FeatureHub Client SDK","description":"FeatureHub client/browser SDK for feature flags, remote configuration, and A/B testing. This package is designed for browser environments (or any non-Node.js context) and uses Server-Sent Events (SSE) for real-time updates. Version 2.0.2 requires Node >=20.0.0 and is TypeScript-first (ships types). Key differentiators: edge-compatible, supports catch-and-release mode for local feature flag overrides during development, integrates with React SDK via featurehub-react-sdk, and offers a client-side context for multi-environment support. Releases follow a monthly cadence.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/featurehub-io/featurehub-javascript-sdk","tags":["javascript","feature-flag-api","feature-flag-sdk","feature-experimentation","feature-flag","flag","toggle","feature-toggle","feature-toggle-api","typescript"],"install":[{"cmd":"npm install featurehub-javascript-client-sdk","lang":"bash","label":"npm"},{"cmd":"yarn add featurehub-javascript-client-sdk","lang":"bash","label":"yarn"},{"cmd":"pnpm add featurehub-javascript-client-sdk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package; CommonJS require() will fail. TypeScript imports are identical.","wrong":"const FeatureHubClient = require('featurehub-javascript-client-sdk')","symbol":"FeatureHubClient","correct":"import { FeatureHubClient } from 'featurehub-javascript-client-sdk'"},{"note":"Context helper for creating client instances with environment and user keys.","symbol":"FeatureHubContext","correct":"import { FeatureHubContext } from 'featurehub-javascript-client-sdk'"},{"note":"The main repository class that stores feature states and emits events.","symbol":"ClientFeatureRepository","correct":"import { ClientFeatureRepository } from 'featurehub-javascript-client-sdk'"}],"quickstart":{"code":"import { FeatureHubClient, ClientFeatureRepository } from 'featurehub-javascript-client-sdk';\n\nconst repository = new ClientFeatureRepository();\nconst apiKey = process.env.FEATUREHUB_API_KEY ?? '';\n\nconst client = FeatureHubClient.newClient({\n  apiKey,\n  repository, // optional: if omitted, creates its own\n  context: { // optional user context\n    userKey: 'user123',\n    // ... other attributes\n  },\n}).build();\n\n// Listen for feature changes\nrepository.addListener((features) => {\n  console.log('Features updated:', features);\n});\n\n// Start polling/SSE\nclient.start();\n\n// Get a boolean flag\nsetTimeout(() => {\n  const enabled = repository.isEnabled('my-feature-flag');\n  console.log('Feature enabled:', enabled);\n  client.stop();\n}, 5000);","lang":"typescript","description":"Creates a FeatureHub client with a user context, starts receiving features via SSE, and checks a boolean flag after 5 seconds."},"warnings":[{"fix":"Use the builder pattern: `FeatureHubClient.newClient({...}).build()`.","message":"In v2.0.0, the client construction API changed from `new FeatureHubClient()` to `FeatureHubClient.newClient().build()`. Old instantiation will throw.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Use `import` syntax or dynamic `import()` for CommonJS projects.","message":"The package became ESM-only in v2.0.0. CommonJS `require()` throws 'ERR_REQUIRE_ESM'.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always call `client.start()` before reading features, or listen to the 'ready' event.","message":"`ClientFeatureRepository` events are not emitted until `client.start()` is called. Calling `repository.isEnabled()` before start returns `false` for all flags.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your FeatureHub environment is configured for server-side evaluation and use a server-sdk-api-key.","message":"The `apiKey` must be a server-evaluated API key from FeatureHub; client-evaluated keys are not supported in this SDK (use the Node SDK instead).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to import syntax: `import { FeatureHubClient } from 'featurehub-javascript-client-sdk'`","cause":"Using CommonJS require() on an ESM-only package (v2+)","error":"ERR_REQUIRE_ESM: require() of ES Module not supported"},{"fix":"Use `repository.isEnabled('flag-key')` after setting up the repository on the client.","cause":"Calling isEnabled on the client object instead of the repository","error":"TypeError: client.isEnabled is not a function"},{"fix":"Ensure you pass `apiKey` as a non-empty string to `newClient()`, e.g., `FeatureHubClient.newClient({ apiKey: '...' })`","cause":"Missing or empty `apiKey` in configuration","error":"Error: No API key provided"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}