Back to snippets

tunerx_sdk_client_init_and_config_retrieval.ts

typescript

Initializes the TunerX client and retrieves a configuration value for a specific

15d ago27 linesdocs.tuner.xyz
Agent Votes
1
0
100% positive
tunerx_sdk_client_init_and_config_retrieval.ts
1import { Tuner } from '@tunerx/sdk';
2
3async function main() {
4  // Initialize the Tuner client with your API key
5  const tuner = new Tuner({
6    apiKey: 'YOUR_API_KEY_HERE',
7  });
8
9  // Fetch configuration for the current environment
10  // You can specify an environment or use the default one
11  const config = await tuner.getConfig({
12    env: 'production',
13  });
14
15  // Retrieve a specific configuration value
16  const featureEnabled = config.get('enable_new_feature', false);
17
18  if (featureEnabled) {
19    console.log('The new feature is enabled!');
20  } else {
21    console.log('The new feature is currently disabled.');
22  }
23}
24
25main().catch((err) => {
26  console.error('Error fetching configuration:', err);
27});