Skip to content

Commit e496dc9

Browse files
add quickstart for js fm
1 parent de33d7d commit e496dc9

File tree

3 files changed

+110
-4
lines changed

3 files changed

+110
-4
lines changed

articles/azure-app-configuration/TOC.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
href: quickstart-java-spring-app.md
2525
- name: Python
2626
href: quickstart-python-provider.md
27-
- name: JavaScript/Node.js
27+
- name: Node.js
2828
href: quickstart-javascript-provider.md
2929
- name: Azure Functions
3030
href: quickstart-azure-functions-csharp.md
@@ -42,8 +42,10 @@
4242
href: quickstart-feature-flag-spring-boot.md
4343
- name: Azure Functions
4444
href: quickstart-feature-flag-azure-functions-csharp.md
45-
- name: Python app
45+
- name: Python
4646
href: quickstart-feature-flag-python.md
47+
- name: Node.js
48+
href: quickstart-feature-flag-javascript.md
4749
- name: Azure Kubernetes Service
4850
href: quickstart-feature-flag-azure-kubernetes-service.md
4951
- name: Service integration
@@ -88,7 +90,7 @@
8890
href: enable-dynamic-configuration-java-spring-app.md
8991
- name: Python
9092
href: enable-dynamic-configuration-python.md
91-
- name: JavaScript
93+
- name: Node.js
9294
href: enable-dynamic-configuration-javascript.md
9395
- name: Azure Kubernetes Service
9496
href: enable-dynamic-configuration-azure-kubernetes-service.md
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Quickstart for adding feature flags to JavaScript apps
3+
titleSuffix: Azure App Configuration
4+
description: In this quickstart, add feature flags to a Node.js app and manage them using Azure App Configuration.
5+
author: zhiyuanliang-ms
6+
ms.service: azure-app-configuration
7+
ms.devlang: javascript
8+
ms.topic: quickstart
9+
ms.date: 09/26/2024
10+
ms.author: zhiyuanliang
11+
ms.custom: quickstart, mode-other, devx-track-js
12+
#Customer intent: As an JavaScript developer, I want to use feature flags to control feature availability quickly and confidently.
13+
---
14+
15+
# Quickstart: Add feature flags to a Python app
16+
17+
In this quickstart, you incorporate Azure App Configuration into a Node.js console app to create an end-to-end implementation of feature management. You can use App Configuration to centrally store all your feature flags and control their states.
18+
19+
The JavaScript Feature Management libraries extend the framework with feature flag support. They seamlessly integrate with App Configuration through its JavaScript configuration provider.
20+
21+
The example used in this tutorial is based on the Node.js application introduced in the [quickstart](./quickstart-javascript-provider.md).
22+
23+
## Prerequisites
24+
25+
- Finish the quickstart [Create a JavaScript app with Azure App Configuration](./quickstart-javascript-provider.md).
26+
27+
## Add a feature flag
28+
29+
Add a feature flag called *Beta* to the App Configuration store and leave **Label** and **Description** with their default values. For more information about how to add feature flags to a store using the Azure portal or the CLI, go to [Create a feature flag](./manage-feature-flags.md#create-a-feature-flag).
30+
31+
> [!div class="mx-imgBorder"]
32+
> ![Enable feature flag named Beta](media/add-beta-feature-flag.png)
33+
34+
## Use the feature flag
35+
36+
1. Go to the *app-configuration-quickstart* directory that you created in the quickstart and install the Feature Management by using the `npm install` command.
37+
38+
```console
39+
npm install @microsoft/feature-management
40+
```
41+
42+
1. Open the file *app.js* and update it with the following code.
43+
44+
``` javascript
45+
const sleepInMs = require("util").promisify(setTimeout);
46+
const { load } = require("@azure/app-configuration-provider");
47+
const { FeatureManager, ConfigurationMapFeatureFlagProvider} = require("@microsoft/feature-management")
48+
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
49+
50+
async function run() {
51+
// Connecting to Azure App Configuration using connection string
52+
const settings = await load(connectionString, {
53+
featureFlagOptions: {
54+
enabled: true,
55+
// Note: selectors must be explicitly provided for feature flags.
56+
selectors: [{
57+
keyFilter: "*"
58+
}],
59+
refresh: {
60+
enabled: true,
61+
refreshIntervalInMs: 10_000
62+
}
63+
}
64+
});
65+
66+
// Creating a feature flag provider which uses a map as feature flag source
67+
const ffProvider = new ConfigurationMapFeatureFlagProvider(settings);
68+
// Creating a feature manager which will evaluate the feature flag
69+
const fm = new FeatureManager(ffProvider);
70+
71+
while (true) {
72+
await settings.refresh(); // Refresh to get the latest feature flag settings
73+
const isEnabled = await fm.isEnabled("Beta"); // Evaluate the feature flag
74+
console.log(`Beta is enabled: ${isEnabled}`);
75+
await sleepInMs(5000);
76+
}
77+
}
78+
79+
run().catch(console.error);
80+
```
81+
82+
## Run the application
83+
84+
1. Run your script:
85+
86+
``` console
87+
node app.js
88+
```
89+
90+
1. You will see the following console outputs because the *Beta feature flag is disabled.
91+
92+
``` console
93+
Beta is enabled: false
94+
```
95+
96+
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created previously.
97+
98+
1. Select **Feature manager** and locate the *Beta* feature flag. Enable the flag by selecting the checkbox under **Enabled**.
99+
100+
1. Wait for a few seconds and you will see the console outputs change.
101+
102+
``` console
103+
Beta is enabled: true
104+
```

articles/azure-app-configuration/quickstart-feature-flag-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ms.custom: devx-track-python, mode-other
1515

1616
In this quickstart, you'll create a feature flag in Azure App Configuration and use it to dynamically control Python apps to create an end-to-end implementation of feature management.
1717

18-
The feature management support extends the dynamic configuration feature in App Configuration. These examples in the quickstart build on thePpython apps introduced in the dynamic configuration tutorial. Before you continue, finish the [quickstart](./quickstart-python-provider.md) and the [tutorial](./enable-dynamic-configuration-python.md) to create python apps with dynamic configuration first.
18+
The feature management support extends the dynamic configuration feature in App Configuration. These examples in the quickstart build on the python app introduced in the dynamic configuration tutorial. Before you continue, finish the [quickstart](./quickstart-python-provider.md) and the [tutorial](./enable-dynamic-configuration-python.md) to create python apps with dynamic configuration first.
1919

2020
This library does **not** have a dependency on any Azure libraries. They seamlessly integrate with App Configuration through its Python configuration provider.
2121

0 commit comments

Comments
 (0)