> For the complete documentation index, see [llms.txt](https://docs.abtasty.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.abtasty.com/server-side/integrations/open-feature/open-feature-js/open-feature-js-quick-start.md).

# Quick-start

### Installation

Refer to the [installation](/server-side/integrations/open-feature/open-feature-js/open-feature-js-installation.md) page for installation steps.

### Getting started

Below is a simple example that describes the instantiation of the AB Tasty Provider. Please see the [OpenFeature Documentation](https://docs.openfeature.dev/docs/reference/concepts/evaluation-api) for details on how to use the OpenFeature SDK.

#### Add the AB Tasty provider

```sh
npm install @flagship-io/openfeature-provider-js
```

#### Confirm peer dependencies are installed

```sh
npm install @openfeature/server-sdk
```

#### Register the AB Tasty provider with OpenFeature

```js
const { ABTastyProvider } = require("@flagship.io/openfeature-provider-js");
const { OpenFeature } = require("@openfeature/server-sdk");
const provider = new ABTastyProvider("<ENV_ID>", "<API_KEY>");
await OpenFeature.setProviderAndWait(provider);
```

### Use of OpenFeature with AB Tasty

After the initial setup you can use OpenFeature according to their [documentation](https://openfeature.dev/docs/reference/concepts/evaluation-api).

:warning: The AB Tasty Provider **requires a targeting key** to be set. Often times this should be set when evaluating the value of a flag by [setting an EvaluationContext](https://openfeature.dev/docs/reference/concepts/evaluation-context) which contains the targeting key.

An example flag evaluation

```js
const client = openFeature.getClient();

const context: EvaluationContext = {
  targetingKey: "TARGETING_KEY",
};
const boolValue = await client.getBooleanValue("boolFlag", false, context);
```

#### Server environment

:warning: When running your server in a TypeScript environment, it's essential to call setProviderAndWait within each endpoint to ensure that every request creates a new visitor context with up-to-date feature flag values. This method initializes a new visitor—using the provided targeting key and any additional context—and fetches the latest flag configurations before any flag evaluations occur. Without this step, subsequent requests might operate on outdated visitor data, leading to inconsistent or stale flag evaluations. For more information, please refers to our [JS SDK documentation](/server-side/sdks/js-sdk.md).

An example of this implementation

```js
// Step 1: Start the OpenFeature SDK by providing the environment ID and API key
let provider = new ABTastyProvider("<ENV_ID>", "<API_KEY>");

const client = OpenFeature.getClient();

// Endpoint to get an item
app.get("/item", async (req, res) => {
  // Step 2: Create a new evaluation with a targeting key (visitor ID) and visitor context
  const evaluationContext = {
    targetingKey: visitorId,
    fs_is_vip: true,
  };

  // Step 3: Set context for OpenFeature instance
  OpenFeature.setContext(evaluationContext);

  // Step 4: Set Flagship SDK as provider
  await OpenFeature.setProviderAndWait(provider);

  // Step 5: Get the values of the flags for the visitor
  const fsEnableDiscountValue = await client.getBooleanValue(
    "fs_enable_discount",
    false,
    evaluationContext
  );
  const fsAddToCartBtnColorValue = await client.getStringValue(
    "fs_add_to_cart_btn_color",
    "blue",
    evaluationContext
  );
  const flagNumberValue = await client.getNumberValue(
    "flag_number",
    0,
    evaluationContext
  );
  const flagObjectValue = await client.getObjectValue(
    "flag_object",
    {},
    evaluationContext
  );
  const flagArrayValue = await client.getObjectValue(
    "flag_array",
    [],
    evaluationContext
  );

  res.json({
    item: {
      name: "Flagship T-shirt",
      price: 20,
    },
    fsEnableDiscount: fsEnableDiscountValue,
    fsAddToCartBtnColor: fsAddToCartBtnColorValue,
    flagNumberValue: flagNumberValue,
    flagObjectValue: flagObjectValue,
    flagArrayValue: flagArrayValue,
  });
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.abtasty.com/server-side/integrations/open-feature/open-feature-js/open-feature-js-quick-start.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
