1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-06 01:15:28 +02:00
unleash.unleash/frontend/src/component/onboarding/dialog/snippets/nodejs.md
2024-09-27 12:02:12 +00:00

1.2 KiB
Raw Blame History

1. Install the SDK

npm install unleash-client

2. Run Unleash

const { initialize } = require('unleash-client');

const unleash = initialize({
  url: '<YOUR_API_URL>',
  appName: 'unleash-onboarding-node',
  customHeaders: { Authorization: '<YOUR_API_TOKEN>' },
  metricsInterval: 5000,
});

setInterval(() => {
  console.log('Is enabled', unleash.isEnabled('<YOUR_FLAG>'));
}, 1000);

Production settings

In order to validate the connection, we changed some settings that you might want to revert. We recommend the following default settings.

const { initialize } = require('unleash-client');

const unleash = initialize({
    url: '<YOUR_API_URL>',
    appName: 'unleash-onboarding-node',
    customHeaders: { Authorization: process.env.UNLEASH_API_KEY  },
});

Additional resources

Now that weve validated the connection, you might want to look into more advanced use cases and examples: