Skip to content

Commit 17badda

Browse files
authored
Merge pull request #290282 from MicrosoftDocs/main
Merge main to live, 4 AM
2 parents bf5e311 + 3b3ce38 commit 17badda

20 files changed

+351
-84
lines changed
Loading
Loading
83.3 KB
Loading

articles/azure-app-configuration/TOC.yml

Lines changed: 9 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
@@ -138,6 +140,8 @@
138140
href: howto-feature-filters.md
139141
- name: ASP.NET Core
140142
href: howto-feature-filters-aspnet-core.md
143+
- name: JavaScript
144+
href: howto-feature-filters-javascript.md
141145
- name: Python
142146
href: howto-feature-filters-python.md
143147
- name: Enable features on a schedule
@@ -146,6 +150,8 @@
146150
href: howto-timewindow-filter.md
147151
- name: ASP.NET Core
148152
href: howto-timewindow-filter-aspnet-core.md
153+
- name: JavaScipt
154+
href: howto-timewindow-filter-javascript.md
149155
- name: Roll out features to targeted audience
150156
items:
151157
- name: Overview
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: Enable conditional features with a custom filter in a Node.js application
3+
titleSuffix: Azure App Configuration
4+
description: Learn how to implement a custom feature filter to enable conditional feature flags for your Node.js application.
5+
ms.service: azure-app-configuration
6+
ms.devlang: javascript
7+
author: zhiyuanliang-ms
8+
ms.author: zhiyuanliang
9+
ms.topic: how-to
10+
ms.custom: mode-other, devx-track-js
11+
ms.date: 09/26/2024
12+
---
13+
14+
# Tutorial: Enable conditional features with a custom filter in a JavaScript application
15+
16+
Feature flags can use feature filters to enable features conditionally. To learn more about feature filters, see [Tutorial: Enable conditional features with feature filters](./howto-feature-filters.md).
17+
18+
The example used in this tutorial is based on the Node.js application introduced in the feature management [quickstart](./quickstart-feature-flag-javascript.md). Before proceeding further, complete the quickstart to create a Node.js application with a *Beta* feature flag. Once completed, you must [add a custom feature filter](./howto-feature-filters.md) to the *Beta* feature flag in your App Configuration store.
19+
20+
In this tutorial, you'll learn how to implement a custom feature filter and use the feature filter to enable features conditionally. We are using the Node.js console app as an example, but you can also use the custom feature filter in other JavaScript applications.
21+
22+
## Prerequisites
23+
24+
- Create a [console app with a feature flag](./quickstart-feature-flag-javascript.md).
25+
- [Add a custom feature filter to the feature flag](./howto-feature-filters.md)
26+
27+
## Implement a custom feature filter
28+
29+
You've added a custom feature filter named **Random** with a **Percentage** parameter for your *Beta* feature flag in the prerequisites. Next, you implement the feature filter to enable the *Beta* feature flag based on the chance defined by the **Percentage** parameter.
30+
31+
1. Open the file *app.js* and add the `RandomFilter` with the following code.
32+
33+
``` javascript
34+
class RandomFilter {
35+
name = "Random";
36+
evaluate(context) {
37+
const percentage = context.parameters.Percentage;
38+
const randomNumber = Math.random() * 100;
39+
return randomNumber <= percentage;
40+
}
41+
}
42+
```
43+
44+
You added a `RandomFilter` class that has a single method named `evaluate`, which is called whenever a feature flag is evaluated. In `evaluate`, a feature filter enables a feature flag by returning `true`.
45+
46+
You set the name to of `RandomFilter` to **Random**, which matches the filter name you set in the *Beta* feature flag in Azure App Configuration.
47+
48+
1. Register the `RandomFilter` when creating the `FeatureManager`.
49+
50+
``` javascript
51+
const fm = new FeatureManager(ffProvider, {customFilters: [new RandomFilter()]});
52+
```
53+
54+
## Feature filter in action
55+
56+
When you run the application the configuration provider will load the *Beta* feature flag from Azure App Configuration. The result of the `isEnabled("Beta")` method will be printed to the console. As the `RandomFilter` is implemented and used by the *Beta* feature flag, the result will be `True` 50 percent of the time and `False` the other 50 percent of the time.
57+
58+
Running the application will show that the *Beta* feature flag is sometimes enabled and sometimes not.
59+
60+
``` bash
61+
Beta is enabled: true
62+
Beta is enabled: false
63+
Beta is enabled: false
64+
Beta is enabled: true
65+
Beta is enabled: true
66+
Beta is enabled: false
67+
Beta is enabled: false
68+
Beta is enabled: false
69+
Beta is enabled: true
70+
Beta is enabled: true
71+
```
72+
73+
## Next steps
74+
75+
To learn more about the built-in feature filters, continue to the following tutorials.
76+
77+
> [!div class="nextstepaction"]
78+
> [Enable features on a schedule](./howto-timewindow-filter.md)
79+
80+
> [!div class="nextstepaction"]
81+
> [Roll out features to targeted audience](./howto-targetingfilter.md)

articles/azure-app-configuration/howto-feature-filters.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,15 @@ You can create custom feature filters that enable features based on your specifi
5555
> [!div class="mx-imgBorder"]
5656
> ![Screenshot of the Azure portal, applying new custom filter.](./media/feature-filters/feature-flag-edit-apply-filter.png)
5757
58-
You have successfully added a custom filter to a feature flag. Follow the instructions in the [Next Steps](#next-steps) section to implement the feature filter into your application for the language or platform you are using.
58+
You have successfully added a custom filter to a feature flag.
5959

60-
## Next steps
61-
62-
In this tutorial, you learned the concept of feature filter and added a custom feature filter to a feature flag.
63-
64-
To learn how to implement a custom feature filter, continue to the following tutorial:
60+
1. Continue to the following instructions to implement the feature filter into your application for the language or platform you are using.
6561

66-
> [!div class="nextstepaction"]
67-
> [ASP.NET Core](./howto-feature-filters-aspnet-core.md)
62+
- [ASP.NET Core](./howto-feature-filters-aspnet-core.md)
63+
- [Node.js](./howto-feature-filters-javascript.md)
64+
- [Python](./howto-feature-filters-python.md)
6865

69-
> [!div class="nextstepaction"]
70-
> [Python](./howto-feature-filters-python.md)
66+
## Next steps
7167

7268
To learn more about the built-in feature filters, continue to the following tutorials:
7369

articles/azure-app-configuration/howto-targetingfilter.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,13 @@ In this article, you will learn how to add and configure a targeting filter for
6868
> [!div class="mx-imgBorder"]
6969
> ![Screenshot of the Azure portal, applying new targeting filter.](./media/feature-filters/feature-flag-edit-apply-targeting-filter.png)
7070
71-
Now, you successfully added a targeting filter for your feature flag. This targeting filter will use the targeting rule you configured to enable or disable the feature flag for specific users and groups. Follow the instructions in the [Next Steps](#next-steps) section to learn how it works in your application for the language or platform you are using.
71+
Now, you successfully added a targeting filter for your feature flag. This targeting filter will use the targeting rule you configured to enable or disable the feature flag for specific users and groups.
7272

73-
## Next steps
74-
75-
In this tutorial, you learned the concept of the targeting filter and added it to a feature flag.
73+
1. Continue to the following instructions to use the feature flag with a targeting filter in your application for the language or platform you are using.
7674

77-
To learn how to use the feature flag with a targeting filter in your application, continue to the following tutorial.
75+
- [ASP.NET Core](./howto-targetingfilter-aspnet-core.md)
7876

79-
> [!div class="nextstepaction"]
80-
> [ASP.NET Core](./howto-targetingfilter-aspnet-core.md)
77+
## Next steps
8178

8279
To learn more about the feature filters, continue to the following tutorials:
8380

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: Enable features on a schedule in a Node.js application
3+
titleSuffix: Azure App Configuration
4+
description: Learn how to enable feature flags on a schedule in a Node.js application.
5+
ms.service: azure-app-configuration
6+
ms.devlang: javascript
7+
author: zhiyuanliang-ms
8+
ms.author: zhiyuanliang
9+
ms.topic: how-to
10+
ms.custom: mode-other, devx-track-js
11+
ms.date: 09/26/2024
12+
---
13+
14+
# Tutorial: Enable features on a schedule in a Node.js application
15+
16+
In this tutorial, you use the time window filter to enable a feature on a schedule for a Node.js application.
17+
18+
The example used in this tutorial is based on the Node.js application introduced in the feature management [quickstart](./quickstart-feature-flag-javascript.md). Before proceeding further, complete the quickstart to create a Node.js application with a *Beta* feature flag. Once completed, you must [add a time window filter](./howto-timewindow-filter.md) to the *Beta* feature flag in your App Configuration store.
19+
20+
## Prerequisites
21+
22+
- Create a [Node.js application with a feature flag](./quickstart-feature-flag-javascript.md).
23+
- [Add a time window filter to the feature flag](./howto-timewindow-filter.md)
24+
25+
## Use the time window filter
26+
27+
You've added a time window filter for your *Beta* feature flag in the prerequisites. Next, you'll use the feature flag with the time window filter in your Node.js application.
28+
29+
When you create a feature manager, the built-in feature filters are automatically added to its feature filter collection.
30+
31+
``` javascript
32+
const fm = new FeatureManager(ffProvider);
33+
```
34+
35+
## Time window filter in action
36+
37+
When you run the application, the configuration provider loads the *Beta* feature flag from Azure App Configuration. The result of the `isEnabled("Beta")` method will be printed to the console. If your current time is earlier than the start time set for the time window filter, the *Beta* feature flag will be disabled by the time window filter.
38+
39+
You'll see the following console outputs.
40+
41+
``` bash
42+
Beta is enabled: false
43+
Beta is enabled: false
44+
Beta is enabled: false
45+
Beta is enabled: false
46+
Beta is enabled: false
47+
Beta is enabled: false
48+
```
49+
50+
Once the start time has passed, you'll notice that the *Beta* feature flag is enabled by the time window filter.
51+
52+
You'll see the console outputs change as the *Beta* is enabled.
53+
54+
``` bash
55+
Beta is enabled: false
56+
Beta is enabled: false
57+
Beta is enabled: false
58+
Beta is enabled: false
59+
Beta is enabled: false
60+
Beta is enabled: false
61+
Beta is enabled: true
62+
Beta is enabled: true
63+
Beta is enabled: true
64+
Beta is enabled: true
65+
```
66+
67+
## Next steps
68+
69+
To learn more about the feature filters, continue to the following tutorials.
70+
71+
> [!div class="nextstepaction"]
72+
> [Enable conditional features with feature filters](./howto-feature-filters.md)
73+
74+
> [!div class="nextstepaction"]
75+
> [Roll out features to targeted audience](./howto-targetingfilter.md)

articles/azure-app-configuration/howto-timewindow-filter.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ In this article, you will learn how to add and configure a time window filter fo
3939
> [!div class="mx-imgBorder"]
4040
> ![Screenshot of the Azure portal, applying new time window filter.](./media/feature-filters/feature-flag-edit-apply-timewindow-filter.png)
4141
42-
Now, you successfully added a time window filter to a feature flag. Follow the instructions in the [Next Steps](#next-steps) section to learn how it works in your application for the language or platform you are using.
42+
Now, you successfully added a time window filter to a feature flag.
4343

44-
## Next steps
45-
46-
In this tutorial, you learned the concept of the time window filter and added it to a feature flag.
44+
1. Continue to the following instructions to use the feature flag with a time window filter in your application for the language or platform you are using.
4745

48-
To learn how to use the feature flag with a time window filter in your application, continue to the following tutorial.
46+
- [ASP.NET Core](./howto-timewindow-filter-aspnet-core.md)
47+
- [Node.js](./howto-timewindow-filter-javascript.md)
4948

50-
> [!div class="nextstepaction"]
51-
> [ASP.NET Core](./howto-timewindow-filter-aspnet-core.md)
49+
## Next steps
5250

5351
To learn more about the feature filters, continue to the following tutorials:
5452

articles/azure-app-configuration/index.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ landingContent:
148148
url: quickstart-feature-flag-spring-boot.md
149149
- text: Python app
150150
url: quickstart-feature-flag-python.md
151+
- text: Node.js app
152+
url: quickstart-feature-flag-javascript.md
151153
- linkListType: tutorial
152154
links:
153155
- text: Use feature flags in ASP.NET Core

0 commit comments

Comments
 (0)