App Configuration client library for JavaScript
Azure App Configuration is a managed service that helps developers centralize their application and feature settings simply and securely.
Use the client library for App Configuration to:
- Create flexible key representations and mappings
- Tag keys with labels
- Replay settings from any point in time
Key links:
Getting started
Install the package
npm install @azure/app-configuration
Currently supported environments
- LTS versions of Node.js
- Latest versions of Safari, Chrome, Edge, and Firefox.
See our support policy for more details.
Prerequisites
- An Azure Subscription
- An App Configuration resource
Create an App Configuration resource
You can use the Azure Portal or the Azure CLI to create an Azure App Configuration resource.
Example (Azure CLI):
az appconfig create --name <app-configuration-resource-name> --resource-group <resource-group-name> --location eastus
Authenticate the client
AppConfigurationClient can authenticate using a service principal or using a connection string.
Authenticating with a service principal
Authentication via service principal is done by:
- Creating a credential using the
@azure/identitypackage. - Setting appropriate RBAC rules on your AppConfiguration resource. More information on App Configuration roles can be found here.
Using DefaultAzureCredential
const azureIdentity = require("@azure/identity");
const appConfig = require("@azure/app-configuration");
const credential = new azureIdentity.DefaultAzureCredential();
const client = new appConfig.AppConfigurationClient(
endpoint, // ex: <https://<your appconfig resource>.azconfig.io>
credential
);
More information about @azure/identity can be found here
Sovereign Clouds
To authenticate with a resource in a Sovereign Cloud, you will need to set the authorityHost in the credential options or via the AZURE_AUTHORITY_HOST environment variable.
const { AppConfigurationClient } = require("@azure/app-configuration");
const { DefaultAzureCredential, AzureAuthorityHosts } = require("@azure/identity");
// Create an AppConfigurationClient that will authenticate through AAD in the China cloud
const client = new AppConfigurationClient(
endpoint, // ex: <https://<your appconfig resource>.azconfig.azure.cn>
new DefaultAzureCredential({ authorityHost: AzureAuthorityHosts.AzureChina })
);
More information about @azure/identity can be found here
Authenticating with a connection string
To get the Primary connection string for an App Configuration resource you can use this Azure CLI command:
az appconfig credential list -g <resource-group-name> -n <app-configuration-resource-name> --query "([?name=='Primary'].connectionString)[0]"
And in code you can now create your App Configuration client with the connection string you got from the Azure CLI:
const client = new AppConfigurationClient("<connection string>");
Key concepts
The AppConfigurationClient has some terminology changes from App Configuration in the portal.
- Key/Value pairs are represented as
ConfigurationSettingobjects - Locking and unlocking a setting is represented in the
isReadOnlyfield, which you can toggle usingsetReadOnly.
The client follows a simple design methodology - ConfigurationSetting can be passed into any method that takes a ConfigurationSettingParam or ConfigurationSettingId.
This means this pattern works:
const setting = await client.getConfigurationSetting({
key: "hello"
});
setting.value = "new value!";
await client.setConfigurationSetting(setting);
// fields unrelated to just identifying the setting are simply
// ignored (for instance, the `value` field)
await client.setReadOnly(setting, true);
// delete just needs to identify the setting so other fields are
// just ignored
await client.deleteConfigurationSetting(setting);
or, for example, re-getting a setting:
let setting = await client.getConfigurationSetting({
key: "hello"
});
// re-get the setting
setting = await client.getConfigurationSetting(setting);
Examples
Create and get a setting
const appConfig = require("@azure/app-configuration");
const client = new appConfig.AppConfigurationClient(
"<App Configuration connection string goes here>"
);
async function run() {
const newSetting = await client.setConfigurationSetting({
key: "testkey",
value: "testvalue",
// Labels allow you to create variants of a key tailored
// for specific use-cases like supporting multiple environments.
// /azure/azure-app-configuration/concept-key-value#label-keys
label: "optional-label"
});
let retrievedSetting = await client.getConfigurationSetting({
key: "testkey",
label: "optional-label"
});
console.log("Retrieved value:", retrievedSetting.value);
}
run().catch((err) => console.log("ERROR:", err));
Troubleshooting
Logging
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:
const { setLogLevel } = require("@azure/logger");
setLogLevel("info");
For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.
React Native support
React Native does not support some JavaScript API used by this SDK library so you need to provide polyfills for them. Please see our React Native sample with Expo for more details.
Next steps
The following samples show you the various ways you can interact with App Configuration:
helloworld.ts- Get, set, and delete configuration values.helloworldWithLabels.ts- Use labels to add additional dimensions to your settings for scenarios like beta vs production.optimisticConcurrencyViaEtag.ts- Set values using etags to prevent accidental overwrites.setReadOnlySample.ts- Marking settings as read-only to prevent modification.getSettingOnlyIfChanged.ts- Get a setting only if it changed from the last time you got it.listRevisions.ts- List the revisions of a key, allowing you to see previous values and when they were set.secretReference.ts- SecretReference represents a configuration setting that references as KeyVault secret.featureFlag.ts- Feature flags are settings that follow specific JSON schema for the value.
More in-depth examples can be found in the samples folder on GitHub.
Contributing
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
This module's tests are a mixture of live and unit tests, which require you to have an Azure App Configuration instance. To execute the tests you'll need to run:
rush updaterush build -t @azure/app-configuration- Create a .env file with these contents in the
sdk\appconfiguration\app-configurationfolder:APPCONFIG_CONNECTION_STRING=connection string for your App Configuration instance cd sdk\appconfiguration\app-configurationnpm run test.
View our tests folder for more details.
Related projects

Feedback
Submit and view feedback for