適用於 Node.js 的 Azure App Service 模組Azure App Service modules for Node.js

概觀Overview

Azure App Service 是 Microsoft Azure 的平台即服務 (PaaS) 供應項目。Azure App Service is a platform-as-a-service (PaaS) offering of Microsoft Azure. 建立適用任何平台或裝置的 Web 與行動應用程式。Create web and mobile apps for any platform or device. 整合您的應用程式與 SaaS 解決方案、與內部部署應用程式連接,並使您的商務程序自動化。Integrate your apps with SaaS solutions, connect with on-premises applications, and automate your business processes. Azure 會使用您選擇的共用 VM 資源或專用 VM,在完全受控的虛擬機器 (VM) 上執行您的應用程式。Azure runs your apps on fully managed virtual machines (VMs), with your choice of shared VM resources or dedicated VMs.

App Service 包含先前以 Azure 網站和 Azure 行動服務的形式來獨立提供的 Web 和行動功能。App Service includes the web and mobile capabilities that we previously delivered separately as Azure Websites and Azure Mobile Services. 此外,它也包含可用來自動執行商務程序及裝載雲端 API 的新功能。It also includes new capabilities for automating business processes and hosting cloud APIs. App Service 是單一的整合式服務,可讓您將各種元件 (網站、行動應用程式後端、RESTful API 和商務程序) 撰寫成單一解決方案。As a single integrated service, App Service lets you compose various components -- websites, mobile app back ends, RESTful APIs, and business processes -- into a single solution.

管理套件Management Package

安裝 npm 套件Install the npm package

安裝適用於 Node.js 的 Azure App Service 模組Install the Azure App Service module for Node.js

npm install azure-arm-website

範例Example

此範例會使用 Node.js 在 Azure 上建立網站。This example creates a website on Azure using Node.js.

const msRestAzure = require('ms-rest-azure');
const webSiteManagementClient = require('azure-arm-website');

const subscriptionId = 'your-subscription-id';
const website = 'website001';
const resourceGroup = 'your-resource-group';
const hostingPlan = 'testHostingPlan';
let webSiteClient;

msRestAzure.interactiveLogin().then(credentials => {
  webSiteClient = new webSiteManagementClient(credentials, subscriptionId);
  createWebSite(website).then(website => console.log('Web Site created successfully', website));
});

function createWebSite(webSiteName) {
  const parameters = { location: 'westus', serverFarmId: hostingPlan };
  console.log(`Creating web site:  ${webSiteName}`);
  return webSiteClient.webApps.createOrUpdate(resourceGroup, webSiteName, parameters, null);
}

範例Samples

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