Configure your JavaScript develop environment for Azure
Artikkeli
When creating cloud applications, developers typically prefer to test code on their local workstations before deploying that code to a cloud environment like Azure. Local development gives you the advantage of a wider variety of tools along with a familiar environment.
This article provides setup instructions to create and validate a local development environment that's suitable for JavaScript with Azure.
One-time subscription creation
Azure resources are created within a subscription and resource group.
To use the same authentication code in local development and the remote Azure hosting environment, use the DefaultAzureCredential. Learn more about this managed identity.
In the search bar, enter resource groups and select it.
Select + Create.
Enter your resource group settings:
Property
Value
Subscription
Select your subscription.
Resource group
Enter your resource group name. This resource group name is used as part of a resources URI when you access the Resource Manager (management plane). The name isn't used for control (such as creating a database) or data plane (inserting data into a table).
Region
Select a geographical region for the resource group.
Select Review + create to begin validation.
When validation successes, select Create.
Open the command palette, Ctrl + Shift + P.
Search for create resource group and select it.
Answer the prompts using the following settings:
Prompt
Value
Select subscription
Sign in to Azure if prompted. Select an existing subscription or create an Azure account if you don't have one.
Enter the name of the new resource group.
Enter your resource group name. This resource group name is used as part of a resources URI when you access the Resource Manager (management plane). The name isn't used for control (such as creating a database) or data plane (inserting data into a table).
Select a location for new resources.
Select a geographical region for the resource group.
Log in to Azure:
Azure CLI
az login
Complete the authentication in a browser.
List your subscription names and IDs. Copy the SubscriptionId value to use the next command.
Azure CLI
az account subscription list --output table
Set your default subscription, used by subsequent commands:
Azure CLI
az account set --subscription YOUR_SUBSCRIPTION_ID
Select from a list of locations supported for your subscription. Copy the Name value of a region close to you.
Azure CLI
az account list-locations --output table
Use the following Azure CLI to create a resource group with your subscription name or ID:
Azure CLI
az group create --name"YOUR_RESOURCE_GROUP_NAME"--location YOUR_REGION
For example:
Azure CLI
az group create --name"my-azure-app"--location westus
Working with Azure and the Azure SDK client libraries
The Azure client libraries are provided individually for each service. You install each library based on the Azure service you need to use.
Each new project using Azure should:
Create Azure resources.
Install Azure client libraries from a package manager such as NPM.
Use managed identity to authenticate with the Azure client library, then use configuration information to access specific services.
Securing configuration information
You have several options to store configuration information:
Azure Key Vault to create and maintain secrets, keys, and certificates that access cloud resources, which don't yet offer managed identity access.
Dotenv is a popular npm package to read environment variables from a .env file. Make sure to add the .env file to the .gitignore file so the .env file isn't checked into to source control.
Create environment variables
To use the Azure settings needed by the Azure SDK libraries to access the Azure cloud, set the most common values to environment variables. The following commands set the environment variables for the local workstation.
In the following examples, the client ID is the service principal ID and service principal secret.
set AZURE_SUBSCRIPTION_ID="<REPLACE-WITH-YOUR-AZURE-SUBSCRIPTION-ID>"
set AZURE_TENANT_ID="<REPLACE-WITH-YOUR-AZURE-TENANT-ID>"
set AZURE_CLIENT_ID="<REPLACE-WITH-YOUR-AZURE-CLIENT-ID>"
set AZURE_CLIENT_SECRET="<REPLACE-WITH-YOUR-AZURE-CLIENT-SECRET>"
Replace the values shown in these commands with those of your specific environment variable.
Create .env file
Another common mechanism is to use the DOTENV NPM package to create a .env file for these settings. If you plan to use a .env, make sure to add the file to the .gitignore so you don't check in the file to source control. Add the .env file to git's .ignore file is the standard way to ensure those settings are checked into source control.
Install npm packages
For every project, we recommend that you always create a separate folder, and its own package.json file using the following steps:
Open a terminal, command prompt, or bash shell and create a new folder to the project. Then move into that new folder.
Konsoli
mkdir MY-NEW-PROJECT && cd MY-NEW-PROJECT
Initialize the package file:
Konsoli
npm init -y
This creates the package.json file and initializes the minimum properties.
Install the Azure cl libraries you need, such as this example:
Konsoli
npm install @azure/identity
Use source control with Visual Studio Code
We recommend that you get into the habit of creating a source control repository whenever you start a project. You can do this from Visual Studio Code.
In Visual Studio Code, select the source control icon to open the Source Control explorer, then select Initialize Repository to initialize a local Git repository:
After the repository is initialized, and you have files to store in source control, enter the message Initial commit and select the checkmark to create the initial commit of your source files.
Create a new repository on GitHub and copy the repository URL for the next few step.
In the Visual Studio integrated terminal, use the following git command to add your remote repository to your local repository. Replace YOUR-ALIAS and YOUR-REPOSITORY with your own values.
Liity tapaamissarjaan ja luo skaalattavia tekoälyratkaisuja, jotka perustuvat reaalimaailman käyttötapauksiin muiden kehittäjien ja asiantuntijoiden kanssa.
Tämä oppimispolku opettaa kehittäjiä käyttämään Azure-kehittäjän komentorivikäyttöliittymää ja sen mallijärjestelmää sovellusten luomiseen, määrittämiseen ja käyttöönottoon.
Luo päästä päähän -ratkaisuja Microsoft Azuressa, jotta voit luoda Azure-funktioita, ottaa käyttöön ja hallita verkkosovelluksia, kehittää Azure-tallennustilaa hyödyntäviä ratkaisuja ja paljon muuta.
How to install, uninstall, and verify Azure SDK for JavaScript libraries using npm. Includes details on installing specific versions and preview packages.
Deploying your JavaScript applications to Azure allows you to use the power of cloud computing, ensuring scalability, reliability, and global reach. This guide walks you through various methods to deploy your JavaScript apps to Azure, from manual deployments to automated CI/CD pipelines.