Deploying Node.js cloud application from Cloud9 development environment

Original author: Windows Azure Team
  • Transfer
  • Tutorial
image

This guide describes how to develop, compile, and deploy Node.js applications on Windows Azure using the Cloud9 Integrated Development Environment (IDE).

What will be discussed in this guide:
  • How to create a project in the Cloud9 IDE.
  • How to deploy a project in Windows Azure.
  • How to update a deployed application in Windows Azure.
  • How to move projects between test and production deployments.

Cloud9 IDE is a cross-platform development environment with a web interface. One of Cloud9’s features for Node.js-based projects allows you to directly deploy applications to Windows Azure. In addition, Cloud9 is integrated with the GitHub and BitBucket repositories, making it easy to share projects with other developers.

With Cloud9, you can develop and deploy applications on Windows Azure from most modern browsers and operating systems, and you do not need to install additional tools or SDKs on your local computer. The following describes how to use the Google Chrome browser on a Mac.

Subscription


To get started with Cloud9, you need to subscribe . You can log in to your site with existing GitHub or BitBucket accounts or by creating a Cloud9 account. Available as a free subscription and paid (with advanced functionality). See the Cloud9 IDE for more information .

Creating a Node.js Project


Log in to Cloud9, click the + icon next to My Projects and select Create a new project .

clip_image002

In the Create a new project dialog box, specify the name and type of the project, as well as the access method. Click Create to create the project.

clip_image004

Note. Some settings are available only in the paid version of Cloud9.

Note. When you deploy a Cloud9 project to Windows Azure, its name is not used.

After creating the project, click Start Editing . If this is your first time starting Cloud9, the system will offer a brief overview of the features. To skip the review or watch it later, select Just the editor, please .

clip_image006

To create a Node application, click File and select New File .

clip_image008

A new Untitled1 tab will appear . To create a Node application, on the Untitled1 tab, enter the following code:

var http = require('http'); 
var port = process.env.PORT; 
http.createServer(function(req,res) { 
    res.writeHead(200, { 'Content-Type': 'text/plain' }); 
    res.end('hello azure\n'); 
}).listen(port);

Note. The process.env.PORT variable ensures that the application will use the correct port both when debugging in Cloud9 and when deploying to Windows Azure.

To save the code, select File and then Save as . In the Save As dialog box, specify server.js as the file name and click Save .

Note. In some cases, a warning icon appears indicating that the req variable is not used. Ignore him.

clip_image010

Application launch


Note. The procedure described in this section is suitable for creating the simplest applications. If the application uses external modules, then a different version of Node.js will be needed for the debugging environment. To enable it, select Configure ... from the debug drop-down list and specify the version of Node.js. you need. For example, when using a version of Node.js other than 0.6.x, authentication errors may occur when working with the azure module.

To run the application in the Cloud9 debugger, click Debug .

clip_image012

A results window will appear. Click the specified URL to open the application in a browser window.

clip_image014

The application will look something like this:
To stop . ebugging, click stop .

Create a Windows Azure Account


An account is required to deploy the application to Windows Azure. If you don’t have a Windows Azure account yet, sign up for a trial subscription. To do this, go to http://www.windowsazure.com and click Free Trial in the upper right corner.

Create Deployment


To create a new deployment, select Deploy and click + to create the deployment server.

clip_image018

In the Add a deploy target dialog box, enter a deployment name and then select Windows Azure from the Choose type list . This name will be needed to identify the deployment in Cloud9, but will not be associated with the deployment name in Windows Azure.

If this is your first time deploying Cloud9 for Windows Azure, configure your Windows Azure publishing options. To do this, download and set Cloud9 parameters as described below.

Click Download Windows Azure Settings .

clip_image020

The Windows Azure Management Portal opens, prompting you to download Windows Azure publishing settings. Before starting the download, log in to your Windows Azure account.

Save the publication settings file to a local drive.

In the Add a deploy target dialog box, select Choose File and specify the path to the downloaded file.

Then click Upload .

Click + Create new to create a hosted service. A hosted service is the container that hosts the application when deployed to Windows Azure. For more information, see "Understanding Creating a Hosted Service for Windows Azure . "

clip_image022

The system will ask you to enter the name of the hosted service and configuration parameters (number of instances, OS, and data center). The specified deployment name will be used as the hosted service name in Windows Azure. This name must be unique on Windows Azure.

clip_image024

Note. The Add a deploy target dialog box, under Choose existing deployment, lists all hosted Windows Azure services. To deploy a project to a specific service, select it from this list.

Note. To enable Remote Desktop for deployment, select Enable RDP and provide credentials.

Windows Azure deployment


Select the deployment you created in the previous steps. A dialog box opens with information about this deployment and the working URL at which to deploy to Windows Azure.

clip_image026

Choose Deploy to Production environment . To start the deployment, click Deploy .

If this is the first time you are deploying this project to Windows Azure, you will receive a No web.config found error message . Click Yes to create the missing file. As a result, the Web.cloud.config file will be added to the project.

clip_image028

If this is the first time you are deploying this project to Windows Azure, you will receive the No 'csdef' file present error message . Click Yes to create the missing file. .csdef. As a result, the ServiceDefinition.csdef file will be added to the project. The ServiceDefinition.csdef file is required to publish the application to Windows Azure. For more information, see "Understanding Creating a Hosted Service for Windows Azure . "

The system will ask you to specify the instance size for this application. Select Small and click Create. . For more information about the sizes of a Windows Azure virtual machine, see the "How to Set the Size of a Virtual Machine " section .

clip_image030

The deployment status will display the progress of the process. When the deployment is complete, Active appears .

clip_image032

Note. Projects deployed to Windows Azure through Cloud 9 are assigned a GUID as the name.

The deployment dialog specifies the working URL. When the process is complete, click the URL to open the application deployed to Windows Azure in a browser.

clip_image034

Application update


To make changes to an application, you can update it on the same hosted Windows Azure service using Cloud9.

In the server.js file, change the code so that the message hello azure v2 is displayed. For example, replace the existing code with the one below.

var http = require('http'); 
var port = process.env.PORT; 
http.createServer(function(req,res) { 
    res.writeHead(200, { 'Content-Type': 'text/plain' }); 
    res.end('hello azure v2\n'); 
}).listen(port);

To save the code, select File and then Save .

Deploying an update in a Windows Azure test environment


Choose Deploy to Staging . To start the deployment, click Deploy .

All hosted Windows Azure services support two environments — test and production. The test environment is similar to the working one, except that the application in the test environment is accessed using the GUID-based conditional URL created by Windows Azure. The application can be tested first in a test environment, and then moved to a production environment by swapping to a virtual IP address (VIP), as described below.

When you deploy the application in a test environment, the console will display a test URL based on the GUID, as shown in the screenshot below. To open the application in a test environment in a browser, click this URL.

clip_image036

Moving an update to a production environment using VIP swap


When deployed in a test or production environment, each service is assigned a virtual IP address (VIP). Therefore, to move a service from a test environment to a production one, instead of redeploying the service, you can swap the VIP. In this case, the application will be moved from the test environment to the working environment without stopping its functioning. For more information, see "Understanding Deployment Management in Windows Azure."

In the deployment dialog box, click the Open portal link to go to the Windows Azure Management Portal.

clip_image038

Sign in with your credentials.

On the left side of the web page, select Hosted Services , Storage Accounts & CDN and click Hosted Services .

clip_image040

The results pane displays the hosted service name defined in Cloud9, and two deployments — one with Environment Staging and the other with Production .

To swap a VIP, select the hosted service and click Swap VIP on the ribbon.

clip_image042

In the opening VIP Swap dialog box, click The OK .

Go to the application in a production environment. Please note that the application has moved from a test environment to a working one.

clip_image044

Using Remote Desktop


If you used RDP when creating the deployment, and also provided a username and password, now you can connect to the hosted service through the remote desktop by selecting the required instance and clicking Connect on the ribbon.

clip_image046

When you click on the Connect button, the system will offer to download the .RDP file. This file contains the information needed to create a remote desktop session. Open this file on Windows, enter the username and password that you specified when creating the deployment, and then establish a connection to the desktop of the selected instance.

Note. The .RDP file used to communicate with hosted instances of the application only works with the Windows Remote Desktop Tool.

Stop and uninstall an application


Windows Azure registers role instances every hour the server runs, and server uptime includes a deployment period, even if the instances were not running. In addition, server uptime takes into account deployment in both test and production environments.

Cloud9 is just a development environment and does not allow you to directly stop or uninstall an application deployed to Windows Azure. Чтобы удалить приложение из Windows Azure, выполните следующие действия:

In the deployment dialog box, click the Open portal link to go to the Windows Azure Management Portal.

clip_image038[1]

Sign in with your credentials. On the left side of the web page, select Hosted Services , Storage Accounts & CDN and click Hosted Services .

Select a test environment (see the value of the Environment field ). To delete the application, click Delete on the ribbon.

clip_image048

Similarly, to uninstall the application, select the work environment and click Delete .

Additional resources