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
#Customer intent: As a JavaScript developer, I want to manage all my app settings in one place.
13
13
---
14
14
# Create a Node.js app with the Azure SDK for JavaScript
15
15
16
16
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,76 +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 your App Configuration connection string
72
-
73
-
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:
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:
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:
If you use macOS, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
If you use Linux, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
Using the Windows command prompt, restart the command prompt to allow the change to take effect and run the following command:
112
-
113
-
```cmd
114
-
echo %AZURE_APPCONFIG_CONNECTION_STRING%
115
-
```
116
-
117
-
### [PowerShell](#tab/powershell)
118
-
119
-
If you use Windows PowerShell, run the following command:
120
-
121
-
```azurepowershell
122
-
$Env:AZURE_APPCONFIG_CONNECTION_STRING
123
-
```
124
-
125
-
### [macOS](#tab/unix)
126
-
127
-
If you use macOS, run the following command:
128
-
129
-
```console
130
-
echo "$AZURE_APPCONFIG_CONNECTION_STRING"
131
-
```
132
-
133
-
### [Linux](#tab/linux)
134
-
135
-
If you use Linux, run the following command:
136
-
137
-
```console
138
-
echo "$AZURE_APPCONFIG_CONNECTION_STRING"
139
-
```
140
-
141
71
## Code samples
142
72
143
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.
@@ -158,12 +88,31 @@ Learn below how to:
158
88
159
89
### Connect to an App Configuration store
160
90
161
-
The following code snippet creates an instance of **AppConfigurationClient** using the connection string stored in your environment variables.
91
+
The following code snippet creates an instance of **AppConfigurationClient**. You can connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
92
+
93
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
94
+
95
+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
313
+
run().catch(console.error);
338
314
```
315
+
---
316
+
317
+
## Configure an environment variable
318
+
319
+
1. Configure an environment variable using Microsoft Entra ID (recommended) or a connection string.
320
+
321
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
322
+
323
+
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.
324
+
325
+
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.
346
+
347
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
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:
367
+
368
+
```console
369
+
node app.js
370
+
```
371
+
372
+
You should see the following output:
373
+
374
+
```output
375
+
Azure App Configuration - JavaScript example
376
+
377
+
Retrieved configuration setting:
378
+
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
379
+
380
+
Added configuration setting:
381
+
Key: TestApp:Settings:NewSetting, Value: New setting value
382
+
383
+
Retrieved list of configuration settings:
384
+
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
385
+
Key: TestApp:Settings:NewSetting, Value: New setting value
386
+
387
+
Read-only status for TestApp:Settings:NewSetting: true
388
+
389
+
Read-only status for TestApp:Settings:NewSetting: false
390
+
391
+
Updated configuration setting:
392
+
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
393
+
394
+
Deleted configuration setting:
395
+
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
0 commit comments