page_type | languages | products | description | urlFragment | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
This sample demonstrates how to manage your Azure virtual machines using a Node.js client and specifically how to: create a virtual machine, start a virtual machine, stop a virtual machine, list virtual machines, delete a virtual machine |
compute-node-manage-vm |
Azure Virtual Machines Management Samples - Node.js
This sample demonstrates how to manage your Azure virtual machines using a Node.js client and specifically how to:
- Create a virtual machine
- Start a virtual machine
- Stop a virtual machine
- List virtual machines
- Delete a virtual machine
On this page
Run this sample
-
If you don't already have it, get Node.js.
-
Clone the repository.
git clone https://github.com/Azure-Samples/compute-node-manage-vm.git
-
Install the dependencies.
cd compute-node-manage-vm npm install
-
Create an Azure service principal either through Azure CLI:
az ad sp create-for-rbac --name YOUR-SERVICE-PRINCIPAL-NAME
Other ways to create a service principal:
-
Set the following environment variables using the information from the service principle that you created.
export AZURE_SUBSCRIPION_ID={your subscription id} export AZURE_CLIENT_ID={your client/app id} export AZURE_CLIENT_SECRET={your client secret/password} export AZURE_TENANT_ID={your tenant id as a guid OR the domain name of your org <contosocorp.com>}
[AZURE.NOTE] On Windows, use
set
instead ofexport
. -
Run the sample.
node index.js
When this script is complete, it returns
success YOUR-RESOURCE-GRUOP-NAME
. -
To clean up after index.js, run the cleanup script, using the resource group name from the previous script's success statement.
node cleanup.js YOUR-RESOURCE-GRUOP-NAME
What does index.js do?
The sample creates, lists, restarts and deletes virtual machines. It starts by logging in using your service principal.
More information
Please refer to Azure SDK for Node for more information. Additionally, here some other helpful links:
- Azure JavaScript Development Center
- Azure Virtual Machines documentation
- Learning Path for Virtual Machines
If you don't have a Microsoft Azure subscription you can get a FREE trial account here.