Skip to content

Commit a818e3e

Browse files
revert to use connectionstring only
1 parent c80b5af commit a818e3e

File tree

2 files changed

+51
-180
lines changed

2 files changed

+51
-180
lines changed

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

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,15 @@ In this tutorial, you create a Node.js console app and load the feature flag fro
5959

6060
1. Create a file named *app.js* in the *feature-management-quickstart* directory and copy the following code.
6161

62-
### [Use Azure Credential (Recommended)](#tab/azurecredential)
63-
6462
``` javascript
6563
const sleepInMs = require("util").promisify(setTimeout);
6664
const { load } = require("@azure/app-configuration-provider");
67-
const { getDefaultAzureCredential } = require("@azure/identity");
6865
const { FeatureManager, ConfigurationMapFeatureFlagProvider} = require("@microsoft/feature-management")
69-
const endpoint = process.env.AZURE_APPCONFIG_ENDPOINT;
66+
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
7067

7168
async function run() {
72-
// Connect to Azure App Configuration using an endpoint with credential.
73-
// To learn more about Azure credential, please refer to
74-
// https://learn.microsoft.com/javascript/api/overview/azure/identity-readme#defaultazurecredential
75-
const settings = await load(endpoint, getDefaultAzureCredential(), {
69+
// Connect to Azure App Configuration using connection string
70+
const settings = await load(connectionString, {
7671
featureFlagOptions: {
7772
enabled: true,
7873
// Note: selectors must be explicitly provided for feature flags.
@@ -102,51 +97,45 @@ In this tutorial, you create a Node.js console app and load the feature flag fro
10297
run().catch(console.error);
10398
```
10499

105-
### [Use Connection String](#tab/connectionstring)
100+
## Run the application
106101

107-
``` javascript
108-
const sleepInMs = require("util").promisify(setTimeout);
109-
const { load } = require("@azure/app-configuration-provider");
110-
const { FeatureManager, ConfigurationMapFeatureFlagProvider} = require("@microsoft/feature-management")
111-
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
102+
1. Set an environment variable named **AZURE_APPCONFIG_CONNECTION_STRING**, and set it to the connection string of your App Configuration store. At the command line, run the following command:
112103

113-
async function run() {
114-
// Connect to Azure App Configuration using connection string
115-
const settings = await load(connectionString, {
116-
featureFlagOptions: {
117-
enabled: true,
118-
// Note: selectors must be explicitly provided for feature flags.
119-
selectors: [{
120-
keyFilter: "*"
121-
}],
122-
refresh: {
123-
enabled: true,
124-
refreshIntervalInMs: 10_000
125-
}
126-
}
127-
});
104+
### [Windows command prompt](#tab/windowscommandprompt)
128105

129-
// Create a feature flag provider which uses a map as feature flag source
130-
const ffProvider = new ConfigurationMapFeatureFlagProvider(settings);
131-
// Create a feature manager which will evaluate the feature flag
132-
const fm = new FeatureManager(ffProvider);
106+
To run the app locally using the Windows command prompt, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
133107

134-
while (true) {
135-
await settings.refresh(); // Refresh to get the latest feature flag settings
136-
const isEnabled = await fm.isEnabled("Beta"); // Evaluate the feature flag
137-
console.log(`Beta is enabled: ${isEnabled}`);
138-
await sleepInMs(5000);
139-
}
140-
}
108+
```cmd
109+
setx AZURE_APPCONFIG_CONNECTION_STRING "<app-configuration-store-connection-string>"
110+
```
141111

142-
run().catch(console.error);
112+
### [PowerShell](#tab/powershell)
113+
114+
If you use Windows PowerShell, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
115+
116+
```azurepowershell
117+
$Env:AZURE_APPCONFIG_CONNECTION_STRING = "<app-configuration-store-connection-string>"
143118
```
144119

145-
---
120+
### [macOS](#tab/unix)
146121

147-
## Run the application
122+
If you use macOS, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
123+
124+
```console
125+
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
126+
```
127+
128+
### [Linux](#tab/linux)
129+
130+
If you use Linux, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
131+
132+
```console
133+
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
134+
```
135+
136+
---
148137

149-
1. Run your script:
138+
1. Run the following command to run the app locally:
150139

151140
``` console
152141
node app.js

articles/azure-app-configuration/quickstart-javascript-provider.md

Lines changed: 18 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -68,46 +68,10 @@ Create a file named *app.js* in the *app-configuration-quickstart* directory and
6868

6969
### Sample 1: Load key-values with default selector
7070

71-
In this sample, you connect to Azure App Configuration and load key-values without specifying advanced options. By default, it loads all key-values with no label. You can either use Azure credential or connection string to connect to Azure App Configuration.
71+
In this sample, you connect to Azure App Configuration using a connection string and load key-values without specifying advanced options.
72+
By default, it loads all key-values with no label.
7273

73-
### [Use Azure Credential (Recommended)](#tab/azurecredential)
74-
75-
``` javascript
76-
const { load } = require("@azure/app-configuration-provider");
77-
const { getDefaultAzureCredential } = require("@azure/identity");
78-
const endpoint = process.env.AZURE_APPCONFIG_ENDPOINT;
79-
80-
async function run() {
81-
console.log("Sample 1: Load key-values with default selector");
82-
83-
// Connect to Azure App Configuration using an endpoint with credential and load all key-values with null label.
84-
// To learn more about Azure credential, please refer to
85-
// https://learn.microsoft.com/javascript/api/overview/azure/identity-readme#defaultazurecredential
86-
const settings = await load(endpoint, getDefaultAzureCredential());
87-
88-
console.log("---Consume configuration as a Map---");
89-
// Find the key "message" and print its value.
90-
console.log('settings.get("message"):', settings.get("message")); // settings.get("message"): Message from Azure App Configuration
91-
// Find the key "app.greeting" and print its value.
92-
console.log('settings.get("app.greeting"):', settings.get("app.greeting")); // settings.get("app.greeting"): Hello World
93-
// Find the key "app.json" whose value is an object.
94-
console.log('settings.get("app.json"):', settings.get("app.json")); // settings.get("app.json"): { myKey: 'myValue' }
95-
96-
console.log("---Consume configuration as an object---");
97-
// Construct configuration object from loaded key-values, by default "." is used to separate hierarchical keys.
98-
const config = settings.constructConfigurationObject();
99-
// Use dot-notation to access configuration
100-
console.log("config.message:", config.message); // config.message: Message from Azure App Configuration
101-
console.log("config.app.greeting:", config.app.greeting); // config.app.greeting: Hello World
102-
console.log("config.app.json:", config.app.json); // config.app.json: { myKey: 'myValue' }
103-
}
104-
105-
run().catch(console.error);
106-
```
107-
108-
### [Use Connection String](#tab/connectionstring)
109-
110-
``` javascript
74+
```javascript
11175
const { load } = require("@azure/app-configuration-provider");
11276
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
11377

@@ -137,55 +101,14 @@ async function run() {
137101
run().catch(console.error);
138102
```
139103

140-
---
141-
142104
### Sample 2: Load specific key-values using selectors
143105

144106
In this sample, you load a subset of key-values by specifying the `selectors` option.
145107
Only keys starting with "app." are loaded.
146108
Note that you can specify multiple selectors based on your needs, each with `keyFilter` and `labelFilter` properties.
147109

148-
### [Use Azure Credential (Recommended)](#tab/azurecredential)
149-
150110
```javascript
151111
const { load } = require("@azure/app-configuration-provider");
152-
const { getDefaultAzureCredential } = require("@azure/identity");
153-
const endpoint = process.env.AZURE_APPCONFIG_ENDPOINT;
154-
155-
async function run() {
156-
console.log("Sample 2: Load specific key-values using selectors");
157-
158-
// Load a subset of keys starting with "app." prefix.
159-
const settings = await load(endpoint, getDefaultAzureCredential(), {
160-
selectors: [{
161-
keyFilter: "app.*"
162-
}],
163-
});
164-
165-
console.log("---Consume configuration as a Map---");
166-
// The key "message" is not loaded as it does not start with "app."
167-
console.log('settings.has("message"):', settings.has("message")); // settings.has("message"): false
168-
// The key "app.greeting" is loaded
169-
console.log('settings.has("app.greeting"):', settings.has("app.greeting")); // settings.has("app.greeting"): true
170-
// The key "app.json" is loaded
171-
console.log('settings.has("app.json"):', settings.has("app.json")); // settings.has("app.json"): true
172-
173-
console.log("---Consume configuration as an object---");
174-
// Construct configuration object from loaded key-values
175-
const config = settings.constructConfigurationObject({ separator: "." });
176-
// Use dot-notation to access configuration
177-
console.log("config.message:", config.message); // config.message: undefined
178-
console.log("config.app.greeting:", config.app.greeting); // config.app.greeting: Hello World
179-
console.log("config.app.json:", config.app.json); // config.app.json: { myKey: 'myValue' }
180-
}
181-
182-
run().catch(console.error);
183-
```
184-
185-
### [Use Connection String](#tab/connectionstring)
186-
187-
``` javascript
188-
const { load } = require("@azure/app-configuration-provider");
189112
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
190113

191114
async function run() {
@@ -218,52 +141,13 @@ async function run() {
218141
run().catch(console.error);
219142
```
220143

221-
---
222-
223144
### Sample 3: Load key-values and trim prefix from keys
224145

225146
In this sample, you load key-values with an option `trimKeyPrefixes`.
226147
After key-values are loaded, the prefix "app." is trimmed from all keys.
227148
This is useful when you want to load configurations that are specific to your application by filtering to a certain key prefix, but you don't want your code to carry the prefix every time it accesses the configuration.
228149

229-
### [Use Azure Credential (Recommended)](#tab/azurecredential)
230-
231-
``` javascript
232-
const { load } = require("@azure/app-configuration-provider");
233-
const { getDefaultAzureCredential } = require("@azure/identity");
234-
const endpoint = process.env.AZURE_APPCONFIG_ENDPOINT;
235-
236-
async function run() {
237-
console.log("Sample 3: Load key-values and trim prefix from keys");
238-
239-
// Load all key-values with no label, and trim "app." prefix from all keys.
240-
const settings = await load(endpoint, getDefaultAzureCredential(), {
241-
selectors: [{
242-
keyFilter: "app.*"
243-
}],
244-
trimKeyPrefixes: ["app."]
245-
});
246-
247-
console.log("---Consume configuration as a Map---");
248-
// The original key "app.greeting" is trimmed as "greeting".
249-
console.log('settings.get("greeting"):', settings.get("greeting")); // settings.get("greeting"): Hello World
250-
// The original key "app.json" is trimmed as "json".
251-
console.log('settings.get("json"):', settings.get("json")); // settings.get("json"): { myKey: 'myValue' }
252-
253-
console.log("---Consume configuration as an object---");
254-
// Construct configuration object from loaded key-values with trimmed keys.
255-
const config = settings.constructConfigurationObject();
256-
// Use dot-notation to access configuration
257-
console.log("config.greeting:", config.greeting); // config.greeting: Hello World
258-
console.log("config.json:", config.json); // config.json: { myKey: 'myValue' }
259-
}
260-
261-
run().catch(console.error);
262-
```
263-
264-
### [Use Connection String](#tab/connectionstring)
265-
266-
``` javascript
150+
```javascript
267151
const { load } = require("@azure/app-configuration-provider");
268152
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
269153

@@ -295,42 +179,40 @@ async function run() {
295179
run().catch(console.error);
296180
```
297181

298-
---
299-
300182
## Run the application
301183

302-
1. Set an environment variable named **AZURE_APPCONFIG_ENDPOINT** or **AZURE_APPCONFIG_CONNECTION_STRING**, depending on the method you used to connect to App Config. Set its value to the endpoint or connection string of your App Configuration store. The following example shows how to set an environment variable to store the connection string on different platforms.
184+
1. Set an environment variable named **AZURE_APPCONFIG_CONNECTION_STRING**, and set it to the connection string of your App Configuration store. At the command line, run the following command:
303185

304186
### [Windows command prompt](#tab/windowscommandprompt)
305187

306-
To run the app locally using the Windows command prompt, run the following command and replace `<app-configuration-store-endpoint>` with the endpoint of your app configuration store:
188+
To run the app locally using the Windows command prompt, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
307189

308190
```cmd
309-
setx AZURE_APPCONFIG_ENDPOINT "<app-configuration-store-endpoint>"
191+
setx AZURE_APPCONFIG_CONNECTION_STRING "<app-configuration-store-connection-string>"
310192
```
311193
312194
### [PowerShell](#tab/powershell)
313195
314-
If you use Windows PowerShell, run the following command and replace `<app-configuration-store-endpoint>` with the endpoint of your app configuration store:
196+
If you use Windows PowerShell, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
315197
316198
```azurepowershell
317-
$Env:AZURE_APPCONFIG_ENDPOINT = "<app-configuration-store-endpoint>"
199+
$Env:AZURE_APPCONFIG_CONNECTION_STRING = "<app-configuration-store-connection-string>"
318200
```
319201
320202
### [macOS](#tab/unix)
321203
322-
If you use macOS, run the following command and replace `<app-configuration-store-endpoint>` with the endpoint of your app configuration store:
204+
If you use macOS, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
323205
324206
```console
325-
export AZURE_APPCONFIG_ENDPOINT='<app-configuration-store-endpoint>'
207+
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
326208
```
327209
328210
### [Linux](#tab/linux)
329211
330-
If you use Linux, run the following command and replace `<app-configuration-store-endpoint>` with the endpoint of your app configuration store:
212+
If you use Linux, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
331213
332214
```console
333-
export AZURE_APPCONFIG_ENDPOINT='<app-configuration-store-endpoint>'
215+
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
334216
```
335217
336218
---
@@ -342,31 +224,31 @@ run().catch(console.error);
342224
Using the Windows command prompt, restart the command prompt to allow the change to take effect and run the following command:
343225
344226
```cmd
345-
echo %AZURE_APPCONFIG_ENDPOINT%
227+
echo %AZURE_APPCONFIG_CONNECTION_STRING%
346228
```
347229
348230
### [PowerShell](#tab/powershell)
349231
350232
If you use Windows PowerShell, run the following command:
351233
352234
```azurepowershell
353-
$Env:AZURE_APPCONFIG_ENDPOINT
235+
$Env:AZURE_APPCONFIG_CONNECTION_STRING
354236
```
355237
356238
### [macOS](#tab/unix)
357239
358240
If you use macOS, run the following command:
359241
360242
```console
361-
echo "$AZURE_APPCONFIG_ENDPOINT"
243+
echo "$AZURE_APPCONFIG_CONNECTION_STRING"
362244
```
363245
364246
### [Linux](#tab/linux)
365247
366248
If you use Linux, run the following command:
367249
368250
```console
369-
echo "$AZURE_APPCONFIG_ENDPOINT"
251+
echo "$AZURE_APPCONFIG_CONNECTION_STRING"
370252
```
371253
372254
---
@@ -428,4 +310,4 @@ run().catch(console.error);
428310
In this quickstart, you created a new App Configuration store and learned how to access key-values using the App Configuration JavaScript provider in a Node.js app. To learn how to configure your app to dynamically refresh configuration settings, continue to the next tutorial.
429311
430312
> [!div class="nextstepaction"]
431-
> [Enable dynamic configuration](./enable-dynamic-configuration-javascript.md)
313+
> [Enable dynamic configuration](./enable-dynamic-configuration-javascript.md)

0 commit comments

Comments
 (0)