適用於 Node.js 的 Azure 虛擬機器模組Azure Virtual Machine Modules for Node.js

概觀Overview

透過適用於 Node.js 的 Azure 管理模組,從您的程式碼定義、設定及部署新的 Windows 和 Linux 虛擬機器和虛擬機器擴展集。Define, configure, and deploy new Windows and Linux virtual machines and virtual machine scale sets from your code with the Azure management modules for Node.js. 這些模組可讓您啟動和停止現有的虛擬機器,以及對您 Azure 訂用帳戶中已停止的 VM 連結或卸離磁碟。The modules let you start and stop existing virtual machines and attach or detach disks to stopped VMs in your Azure subscription.

管理封裝Management package

安裝 npm 模組Install the npm module

安裝 Azure 計算 npm 模組Install the Azure Compute npm module

npm install azure-arm-compute

範例Example

下列範例說明如何登入 Azure、建立管理用戶端,並列出所指定位置、發行者、供應項目和 SKU 的所有 VM 映像。The following example illustrates how to log in to Azure, create a management client, and list all VM images for the specified location, publisher, offer, and SKU.

const msRestAzure = require('ms-rest-azure');
const computeManagementClient = require('azure-arm-compute');

const subscriptionId = 'my-subscription-id';

msRestAzure.interactiveLogin().then(credentials => {
  const client = new computeManagementClient(credentials, subscriptionId);

  client.virtualMachineImages
    .list(
        'westus',                   // location
        'Canonical',   // publisher name
        'UbuntuServer',            // offer
        '16.04-LTS'        // sku
    )
    .then(result => console.log(result));
});

範例Samples

虛擬機器管理Virtual machine management
Node.js 的 Azure 虛擬機器管理範例Azure virtual machines management sample with Node.js 示範如何建立、列出、重新啟動及刪除虛擬機器。Demonstrates how to create, list, restart, and delete virtual machines.

深入探索可在應用程式中使用的 Node.js 程式碼範例Explore more sample Node.js code you can use in your apps.