Skip to content

Commit 2bb5194

Browse files
add feature filter doc
1 parent 606771c commit 2bb5194

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

articles/azure-app-configuration/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
href: howto-feature-filters.md
139139
- name: ASP.NET Core
140140
href: howto-feature-filters-aspnet-core.md
141+
- name: Node.js
142+
href: howto-feature-filters-javascript.md
141143
- name: Python
142144
href: howto-feature-filters-python.md
143145
- name: Enable features on a schedule
@@ -146,6 +148,8 @@
146148
href: howto-timewindow-filter.md
147149
- name: ASP.NET Core
148150
href: howto-timewindow-filter-aspnet-core.md
151+
- name: Node.js
152+
href: howto-timewindow-filter-javascript.md
149153
- name: Roll out features to targeted audience
150154
items:
151155
- name: Overview
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
ms.custom: devx-track-csharp
8+
author: zhiyuanliang-ms
9+
ms.author: zhiyuanliang
10+
ms.topic: how-to
11+
ms.custom: mode-other, devx-track-js
12+
ms.date: 09/26/2024
13+
---
14+
15+
# Tutorial: Enable conditional features with a custom filter in a Node.js application
16+
17+
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).
18+
19+
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.
20+
21+
In this tutorial, you'll learn how to implement a custom feature filter and use the feature filter to enable features conditionally.
22+
23+
## Prerequisites
24+
25+
- Create a [Node.js app with a feature flag](./quickstart-feature-flag-javascript.md).
26+
- [Add a custom feature filter to the feature flag](./howto-feature-filters.md)
27+
28+
## Implement a custom feature filter
29+
30+
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.
31+
32+
1. Open the file *app.js* and add the `RandomFilter` with the following code.
33+
34+
``` javascript
35+
class RandomFilter {
36+
name = "Random";
37+
evaluate(context) {
38+
const percentage = context.parameters.Percentage;
39+
const randomNumber = Math.random() * 100;
40+
return randomNumber <= percentage;
41+
}
42+
}
43+
```
44+
45+
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`.
46+
47+
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.
48+
49+
1. Register the `RandomFilter` when creating the `FeatureManager`.
50+
51+
``` javascript
52+
const fm = new FeatureManager(ffProvider, {customFilters: [new RandomFilter()]});
53+
```
54+
55+
## Feature filter in action
56+
57+
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.
58+
59+
Running the application will show that the *Beta* feature flag is sometimes enabled and sometimes not.
60+
61+
``` bash
62+
Beta is enabled: true
63+
Beta is enabled: false
64+
Beta is enabled: false
65+
Beta is enabled: true
66+
Beta is enabled: true
67+
Beta is enabled: false
68+
Beta is enabled: false
69+
Beta is enabled: false
70+
Beta is enabled: true
71+
Beta is enabled: true
72+
```
73+
74+
## Next steps
75+
76+
To learn more about the built-in feature filters, continue to the following tutorials.
77+
78+
> [!div class="nextstepaction"]
79+
> [Enable features on a schedule](./howto-timewindow-filter.md)
80+
81+
> [!div class="nextstepaction"]
82+
> [Roll out features to targeted audience](./howto-targetingfilter.md)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ To learn how to implement a custom feature filter, continue to the following tut
6666
> [!div class="nextstepaction"]
6767
> [ASP.NET Core](./howto-feature-filters-aspnet-core.md)
6868
69+
> [!div class="nextstepaction"]
70+
> [Node.js](./howto-feature-filters-javascript.md)
71+
6972
> [!div class="nextstepaction"]
7073
> [Python](./howto-feature-filters-python.md)
7174
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 an ASP.NET Core 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 an ASP.NET Core 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 will be automatically added to its feature filter collection.
30+
31+
``` javascript
32+
// The Microsoft.TimeWindow and Microsoft.Targeting filters are auto-included, so you can use them directly in your feature flags.
33+
const fm = new FeatureManager(ffProvider);
34+
```
35+
36+
## Time window filter in action
37+
38+
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. 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.
39+
40+
Once the start time has passed, you'll notice that the *Beta* feature flag is enabled by the time window filter.
41+
42+
You will see the following console outputs.
43+
44+
``` bash
45+
Beta is enabled: false
46+
Beta is enabled: false
47+
Beta is enabled: false
48+
Beta is enabled: false
49+
Beta is enabled: false
50+
Beta is enabled: false
51+
Beta is enabled: true
52+
Beta is enabled: true
53+
Beta is enabled: true
54+
Beta is enabled: true
55+
```
56+
57+
## Next steps
58+
59+
To learn more about the feature filters, continue to the following tutorials.
60+
61+
> [!div class="nextstepaction"]
62+
> [Enable conditional features with feature filters](./howto-feature-filters.md)
63+
64+
> [!div class="nextstepaction"]
65+
> [Roll out features to targeted audience](./howto-targetingfilter.md)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ To learn how to use the feature flag with a time window filter in your applicati
5050
> [!div class="nextstepaction"]
5151
> [ASP.NET Core](./howto-timewindow-filter-aspnet-core.md)
5252
53+
> [!div class="nextstepaction"]
54+
> [Node.js](./howto-timewindow-filter-javascript.md)
55+
5356
To learn more about the feature filters, continue to the following tutorials:
5457

5558
> [!div class="nextstepaction"]

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)