Quickstart: Create a JavaScript app with Azure App Configuration
In this quickstart, you will use Azure App Configuration to centralize storage and management of application settings using the App Configuration client library for JavaScript.
Prerequisites
- An Azure account with an active subscription. Create one for free.
- An App Configuration store. Create a store.
- LTS versions of Node.js. For information about installing Node.js either directly on Windows or using the Windows Subsystem for Linux (WSL), see Get started with Node.js
Add a key-value
Add the following key-value to the App Configuration store and leave Label and Content Type with their default values. For more information about how to add key-values to a store using the Azure portal or the CLI, go to Create a key-value.
Key | Value |
---|---|
TestApp:Settings:Message | Data from Azure App Configuration |
Setting up the Node.js app
In this tutorial, you'll create a new directory for the project named app-configuration-quickstart.
mkdir app-configuration-quickstart
Switch to the newly created app-configuration-quickstart directory.
cd app-configuration-quickstart
Install the Azure App Configuration client library by using the
npm install
command.npm install @azure/app-configuration
Create a new file called app.js in the app-configuration-quickstart directory and add the following code:
const appConfig = require("@azure/app-configuration");
Configure your connection string
Set an environment variable named AZURE_APP_CONFIG_CONNECTION_STRING, and set it to the access key to your App Configuration store. At the command line, run the following command:
$Env:AZURE_APP_CONFIG_CONNECTION_STRING = "connection-string-of-your-app-configuration-store"
Restart the command prompt to allow the change to take effect. Print out the value of the environment variable to validate that it is set properly.
Connect to an App Configuration store
The following code snippet creates an instance of AppConfigurationClient using the connection string stored in your environment variables.
const connection_string = process.env.AZURE_APP_CONFIG_CONNECTION_STRING;
const client = new appConfig.AppConfigurationClient(connection_string);
Get a configuration setting
The following code snippet retrieves a configuration setting by key
name. The key shown in this example was created in the previous steps of this article.
async function run() {
let retrievedSetting = await client.getConfigurationSetting({
key: "TestApp:Settings:Message"
});
console.log("Retrieved value:", retrievedSetting.value);
}
run().catch((err) => console.log("ERROR:", err));
Build and run the app locally
Run the following command to run the Node.js app:
node app.js
You should see the following output at the command prompt:
Retrieved value: Data from Azure App Configuration
Clean up resources
If you don't want to continue using the resources created in this article, delete the resource group you created here to avoid charges.
Important
Deleting a resource group is irreversible. The resource group and all the resources in it are permanently deleted. Ensure that you don't accidentally delete the wrong resource group or resources. If you created the resources for this article inside a resource group that contains other resources you want to keep, delete each resource individually from its respective pane instead of deleting the resource group.
- Sign in to the Azure portal, and select Resource groups.
- In the Filter by name box, enter the name of your resource group.
- In the result list, select the resource group name to see an overview.
- Select Delete resource group.
- You're asked to confirm the deletion of the resource group. Enter the name of your resource group to confirm, and select Delete.
After a few moments, the resource group and all its resources are deleted.
Next steps
In this quickstart, you created a new App Configuration store and learned how to access key-values from a Node.js app.
For additional code samples, visit:
Feedback
Submit and view feedback for