You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document shows examples of how to use the [Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/appconfiguration/app-configuration) to access key-values in Azure App Configuration.
17
17
18
-
>[!TIP]
18
+
>[!IMPORTANT]
19
19
> App Configuration offers a JavaScript provider library that is built on top of the JavaScript SDK and is designed to be easier to use with richer features. It enables configuration settings to be used like a Map object, and offers other features like configuration composition from multiple labels, key name trimming, and automatic resolution of Key Vault references. Go to the [JavaScript quickstart](./quickstart-javascript-provider.md) to learn more.
20
20
21
21
## Prerequisites
@@ -68,94 +68,6 @@ Add the following key-value to the App Configuration store and leave **Label** a
68
68
> [!NOTE]
69
69
> The code snippets in this example will help you get started with the App Configuration client library for JavaScript. For your application, you should also consider handling exceptions according to your needs. To learn more about exception handling, please refer to our [JavaScript SDK documentation](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/appconfiguration/app-configuration).
70
70
71
-
## Configure an environment variable
72
-
73
-
1. Configure an environment variable using Microsoft Entra ID (recommended) or a connection string.
74
-
75
-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
76
-
77
-
Set an environment variable named **AZURE_APPCONFIG_ENDPOINT** to the endpoint of your App Configuration store found under the **Overview** of your store in the Azure portal.
78
-
79
-
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
Set an environment variable named **AZURE_APPCONFIG_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under **Access keys** of your store in the Azure portal.
100
-
101
-
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
1. Print out the value of the environment variable to validate that it is set properly with the command below.
121
-
122
-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
123
-
124
-
```cmd
125
-
echo AZURE_APPCONFIG_ENDPOINT
126
-
```
127
-
128
-
If you use PowerShell, run the following command:
129
-
130
-
```powershell
131
-
$Env:AZURE_APPCONFIG_ENDPOINT
132
-
```
133
-
134
-
If you use macOS or Linux, run the following command:
135
-
136
-
```bash
137
-
export AZURE_APPCONFIG_ENDPOINT
138
-
```
139
-
140
-
### [Connection string](#tab/connection-string)
141
-
142
-
```cmd
143
-
echo AZURE_APPCONFIG_CONNECTION_STRING
144
-
```
145
-
146
-
If you use PowerShell, run the following command:
147
-
148
-
```powershell
149
-
$Env:AZURE_APPCONFIG_CONNECTION_STRING
150
-
```
151
-
152
-
If you use macOS or Linux, run the following command:
153
-
154
-
```bash
155
-
export AZURE_APPCONFIG_CONNECTION_STRING
156
-
```
157
-
---
158
-
159
71
## Code samples
160
72
161
73
The sample code snippets in this section show you how to perform common operations with the App Configuration client library for JavaScript. Add these code snippets to the body of `run` function in *app-configuration-example.js* file you created earlier.
@@ -190,7 +102,7 @@ const client = new AppConfigurationClient(
190
102
process.env.AZURE_APPCONFIG_ENDPOINT,
191
103
new DefaultAzureCredential()
192
104
);
193
-
105
+
```
194
106
195
107
### [Connection string](#tab/connection-string)
196
108
@@ -400,37 +312,86 @@ run().catch(console.error);
400
312
```
401
313
---
402
314
403
-
In your console window, navigate to the directory containing the *app-configuration-example.js* file and execute the following command to run the app:
404
-
405
-
```console
406
-
node app.js
407
-
```
408
-
409
-
You should see the following output:
410
-
411
-
```output
412
-
Azure App Configuration - JavaScript example
413
-
414
-
Retrieved configuration setting:
415
-
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
416
-
417
-
Added configuration setting:
418
-
Key: TestApp:Settings:NewSetting, Value: New setting value
419
-
420
-
Retrieved list of configuration settings:
421
-
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
422
-
Key: TestApp:Settings:NewSetting, Value: New setting value
315
+
## Configure an environment variable
423
316
424
-
Read-only status for TestApp:Settings:NewSetting: true
317
+
1. Configure an environment variable using Microsoft Entra ID (recommended) or a connection string.
425
318
426
-
Read-only status for TestApp:Settings:NewSetting: false
319
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
320
+
321
+
Set an environment variable named **AZURE_APPCONFIG_ENDPOINT** to the endpoint of your App Configuration store found under the **Overview** of your store in the Azure portal.
322
+
323
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
Set an environment variable named **AZURE_APPCONFIG_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under **Access keys** of your store in the Azure portal.
344
+
345
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
364
+
1. In your console window, navigate to the directory containing the *app-configuration-example.js* file and execute the following command to run the app:
430
365
431
-
Deleted configuration setting:
432
-
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
433
-
```
366
+
```console
367
+
node app.js
368
+
```
369
+
370
+
You should see the following output:
371
+
372
+
```output
373
+
Azure App Configuration - JavaScript example
374
+
375
+
Retrieved configuration setting:
376
+
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
377
+
378
+
Added configuration setting:
379
+
Key: TestApp:Settings:NewSetting, Value: New setting value
380
+
381
+
Retrieved list of configuration settings:
382
+
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
383
+
Key: TestApp:Settings:NewSetting, Value: New setting value
384
+
385
+
Read-only status for TestApp:Settings:NewSetting: true
386
+
387
+
Read-only status for TestApp:Settings:NewSetting: false
388
+
389
+
Updated configuration setting:
390
+
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
391
+
392
+
Deleted configuration setting:
393
+
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
0 commit comments