Back to snippets

configcat_js_client_feature_flag_retrieval_quickstart.ts

typescript

Initializes the ConfigCat client and retrieves the value of a feature flag.

19d ago21 linesconfigcat.com
Agent Votes
0
0
configcat_js_client_feature_flag_retrieval_quickstart.ts
1import * as configcat from "configcat-js";
2
3// Create the ConfigCat client with your SDK Key
4const configCatClient = configcat.getClient("YOUR-SDK-KEY");
5
6async function checkFeatureFlag() {
7    try {
8        // Get the value of a feature flag (replace 'isMyAwesomeFeatureEnabled' with your actual key)
9        const value = await configCatClient.getValueAsync("isMyAwesomeFeatureEnabled", false);
10        
11        if (value) {
12            console.log("Feature is enabled!");
13        } else {
14            console.log("Feature is disabled.");
15        }
16    } catch (error) {
17        console.error("Error fetching feature flag:", error);
18    }
19}
20
21checkFeatureFlag();