Creating a Hello World Windows Azure Node.js Web Application


Node.js is enjoying much popularity and Glenn Block is helping us to bring it on Windows Azure. I have divided this tutorial into the three parts, installing the required SDK, creating Web Applications and then publishing to the Windows Azure portal. The purpose of this tutorial is to help you in setting up an environment and publishing. In further tutorials we will dig deeper.

Install Windows Azure SDK for Node.JS

To start with Node.JS on Windows Azure, you need to install Windows Azure SDK for Node.JS. You can Get Windows Azure SDK for Node.JS from here. You need to install it using the Web Installer. You will get the following dialog box to install Windows Azure SDK for Node.JS

azure1.gif

After successful installation, you should get the following confirmation dialog.

azure2.gif

By this, the SDK has been installed on your machine.

Create Node Application

To create the Node application, click on Start and then select Windows Azure PowerShell for Node.JS. Run this as administrator.

azure3.gif

On the command prompt create a Node directory in the C drive as below:

azure4.gif

After creating the Node directory you need to create a solution. You can create a solution as below:

azure5.gif

I have created a solution called MyApplication. You can see the files created inside the solution are as below:

azure6.gif

There are four files created. If you are coming from a Windows Azure background, you must be aware of the other three files than deploymentSettings.json file. The deploymentSettings.json file stores local setting for Windows Azure PowerShell deployment cmdlets.

Next you need to add a WebRole to the solution. To add a WebRole, execute the following PowerShell command. If you don't provide any name then by default a WebRole name would be WebRole1. However I am using the name WebRoleForNodeJS.

azure7.gif

Now if you list files created inside WebRoleForNodeJS, you will find the configuration files and a JS file.

azure8.gif

The most important file is server.js. This file contains a starter code for Node.JS. You need to add codes in this file. Go ahead and open this file in NotePad. As of now, I am leaving the default code created by the tool.

Server.js

var http = require('http');
var port = process.env.port || 1337;
http.createServer(function (req, res)
{
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello NodeJS from Debugmode\n');
}).listen(port);

Run Locally on Windows Azure Emulator

To run it locally, go ahead and execute the following PS command to start Windows Azure Emulator.

azure9.gif

You can see it running in the emulator as below:

azure10.gif

Publish to Windows Azure Portal

To publish it to the Windows Azure portal, first you need to specify a Publish Setting. You can specify that as below:

azure11.gif

You will be redirected to a live login page. Sign in to download the Publish Setting file. After login you should be able to download PublishSetting file. Download the file inside the Node folder you created in previous steps.

azure12.gif

Next you need to import PublishSetting file as below:

azure13.gif

After importing the PublishSetting file, you can it publish to the Windows Azure portal as below:

azure14.gif

In the above command, name is the unique name and location is one of the Windows Azure Data centers. After successfully publish operation , you should able to see Node.js running on Windows Azure portal.

azure15.gif

This is all that is required to create your first application. In a further article I will discuss much deeper on the subject. I hope this article is useful.

Thanks for reading...

Up Next
    Ebook Download
    View all
    Learn
    View all