EchoVib

@azure/app-configuration

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

Source code | Package (NPM) | API reference documentation | Product documentation | Samples

Getting started

Currently supported environments

  • Node.js version 8.x.x or higher

Prerequisites: You must have an Azure Subscription and an App Configuration resource to use this package.

1. Install the @azure/app-configuration package

npm install @azure/app-configuration

2. 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

3. Create and authenticate an AppConfigurationClient

App Configuration uses connection strings for authentication.

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> 

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 ConfigurationSetting objects
  • Locking and unlocking a setting is renamed to readOnly, which you can toggle using the setReadOnly and clearReadOnly methods.

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); await client.setReadOnly(setting); await client.deleteConfigurationSetting(setting);

or, for example, re-getting a setting:

let setting = await client.getConfigurationSetting({ key: "hello" }); setting = await.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", label: "optional-label" }); let retrievedSetting = await client.getConfigurationSetting("testkey", { label: "optional-label" }); console.log("Retrieved value:", retrievedSetting.value); } run().catch(err => console.log("ERROR:", err));

Next steps

The following samples show you the various ways you can interact with App Configuration:

More in-depth examples can be found in the samples folder on GitHub.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to aContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant usthe rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to providea CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructionsprovided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct.For more information see the Code of Conduct FAQ orcontact opencode@microsoft.com with any additional questions or comments.

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 update
  • rush build -t @azure/app-configuration
  • Create a .env file with these contents in the sdk\appconfiguration\app-configuration folder:
    AZ_CONFIG_CONNECTION=connection string for your App Configuration instance
  • cd sdk\appconfiguration\app-configuration
  • npm run test.
  • View our testsfolder for more details.

    Related projects

    Impressions

    ncG1vNJzZmiZqqq%2Fpr%2FDpJuom6Njr627wWeaqKqVY8SqusOorqxmnprBcHDWnploopGrrrSv0aKnrWeRr8KzsYyap6llk6S7p7XGrqmarJmku3B9jWllaWWgp7K3tcSwZXBnmaOxpsSNoaumpA%3D%3D

    Na Lin

    Update: 2024-06-24