Permalink
Fetching contributors…
Cannot retrieve contributors at this time
202 lines (138 sloc) 6.56 KB
title description services documentationcenter author manager editor ms.assetid ms.service ms.workload ms.tgt_pltfrm ms.devlang ms.topic ms.date ms.author ms.custom
Create a Node.js in Azure App Service on Linux | Microsoft Docs
Deploy your first Node.js Hello World in Azure App Service on Linux in minutes.
app-service\web
msangapu
cfowler
582bb3c2-164b-42f5-b081-95bfcb7a502a
app-service-web
web
na
na
quickstart
06/07/2017
msangapu
mvc

Create a Node.js web app in Azure App Service on Linux

[!NOTE] This article deploys an app to App Service on Linux. To deploy to App Service on Windows, see Create a Node.js web app in Azure.

App Service on Linux provides a highly scalable, self-patching web hosting service using the Linux operating system. This quickstart shows how to deploy a Node.js app to App Service on Linux using the Cloud Shell.

You'll complete this quickstart in Cloud Shell, but you can also run these commands locally with Azure CLI.

Sample app running in Azure

[!INCLUDE quickstarts-free-trial-note]

[!INCLUDE cloud-shell-try-it.md]

Install web app extension for Cloud Shell

To complete this quickstart, you will need to add the az web app extension. If the extension is already installed, you should update it to the latest version. To update the web app extension, type az extension update -n webapp.

To install the webapp extension, run the following command:

az extension add -n webapp

When the extension has been installed, the Cloud Shell shows information to the following example:

The installed extension 'webapp' is in preview.

Download the sample

In the Cloud Shell, create a quickstart directory and then change to it.

mkdir quickstart

cd quickstart

Next, run the following command to clone the sample app repository to your quickstart directory.

git clone https://github.com/Azure-Samples/nodejs-docs-hello-world

While running, it displays information similar to the following example:

Cloning into 'nodejs-docs-hello-world'...
remote: Counting objects: 40, done.
remote: Total 40 (delta 0), reused 0 (delta 0), pack-reused 40
Unpacking objects: 100% (40/40), done.
Checking connectivity... done.

Create a web app

Change to the directory that contains the sample code and run the az webapp up command.

In the following example, replace <app_name> with a unique app name.

cd nodejs-docs-hello-world

az webapp up -n <app_name>

This command may take a few minutes to run. While running, it displays information similar to the following example:

Creating Resource group 'appsvc_rg_Linux_CentralUS' ...
Resource group creation complete
Creating App service plan 'appsvc_asp_Linux_CentralUS' ...
App service plan creation complete
Creating app '<app_name>' ....
Webapp creation complete
Updating app settings to enable build after deployment
Creating zip with contents of dir /home/username/quickstart/nodejs-docs-hello-world ...
Preparing to deploy and build contents to app.
Fetching changes.

Generating deployment script.
Generating deployment script.
Generating deployment script.
Running deployment command...
Running deployment command...
Running deployment command...
Deployment successful.
All done.
{
  "app_url": "https://<app_name>.azurewebsites.net",
  "location": "Central US",
  "name": "<app_name>",
  "os": "Linux",
  "resourcegroup": "appsvc_rg_Linux_CentralUS ",
  "serverfarm": "appsvc_asp_Linux_CentralUS",
  "sku": "STANDARD",
  "src_path": "/home/username/quickstart/nodejs-docs-hello-world ",
  "version_detected": "6.9",
  "version_to_create": "node|6.9"
}

The az webapp up command does the following actions:

  • Create a default resource group.

  • Create a default app service plan.

  • Create an app with the specified name.

  • Zip deploy files from the current working directory to the web app.

Browse to the app

Browse to the deployed application using your web browser. Replace <app_name> with your web app name.

http://<app_name>.azurewebsites.net

The Node.js sample code is running in a web app with built-in image.

Sample app running in Azure

Congratulations! You've deployed your first Node.js app to App Service on Linux.

Update and redeploy the code

In the Cloud Shell, type nano index.js to open the nano text editor.

Nano index.js

Make a small change to the text in the call to response.end:

response.end("Hello Azure!");

Save your changes and exit nano. Use the command ^O to save and ^X to exit.

You'll now redeploy the app. Substitute <app_name> with your web app.

az webapp up -n <app_name>

Once deployment has completed, switch back to the browser window that opened in the Browse to the app step, and refresh the page.

Updated sample app running in Azure

Manage your new Azure web app

Go to the Azure portal to manage the web app you created.

From the left menu, click App Services, and then click the name of your Azure web app.

Portal navigation to Azure web app

You see your web app's Overview page. Here, you can complete basic management tasks like browse, stop, start, restart, and delete.

App Service page in Azure portal

The left menu provides different pages for configuring your app.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, delete the resource group from the Cloud Shell. If you modified the region, update the resource group name appsvc_rg_Linux_CentralUS to the resource group specific to your app.

az group delete --name appsvc_rg_Linux_CentralUS

This command may take a minute to run.

Next steps

[!div class="nextstepaction"] Node.js with MongoDB