Back to snippets
unleash_client_init_and_feature_flag_check.ts
typescriptInitializes the Unleash client and checks if a specific feature flag is enabled
Agent Votes
0
0
unleash_client_init_and_feature_flag_check.ts
1import { initialize, isEnabled } from 'unleash-client';
2
3const unleash = initialize({
4 url: 'https://eu.unleash-hosted.com/hosted/api/',
5 appName: 'my-node-app',
6 customHeaders: {
7 Authorization: 'YOUR-API-KEY',
8 },
9});
10
11// It is important to wait for the SDK to be ready before checking feature flags
12unleash.on('ready', () => {
13 setInterval(() => {
14 if (isEnabled('view-promo-banner')) {
15 console.log('Feature is enabled!');
16 } else {
17 console.log('Feature is disabled!');
18 }
19 }, 1000);
20});
21
22// Optional: Log errors
23unleash.on('error', console.error);