Creating 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. In this tutorial, I will walkthrough step by step to create your first Windows Azure Node.js Web Application. I have divided this tutorial in three parts as installing required SDK, creating Web Application and then publishing to Windows Azure portal. Purpose of this tutorial is to help you in setting up 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 from Web Installer. You will get below dialog box to install Windows Azure SDK for Node.JS

clip_image002

After successful installation, you should get below confirmation dialog .

clip_image004

By this  step SDK has been installed on your machine.

Create Node Application

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

clip_image005

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

clip_image006

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

clip_image007

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

clip_image008

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

Next you need to add a WebRole to the solution. To add WebRole execute below PowerShell command. If you don’t provide any name then by default WebRole name would be WebRole1. However I am providing name as WebRoleForNodeJS

clip_image009

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

clip_image010

Most important file is server.js. This file contains 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 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 below PS command to start Windows Azure Emulator.

clip_image011

You can see is running in emulator as below,

clip_image012

Publish to Windows Azure Portal

To publish it to Windows Azure portal, first you need to take Publish Setting. You can take that as below,

clip_image013

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

clip_image015

Next you need to import PublishSetting file as below,

clip_image016

Note : Publishsettings file only needs to be imported once on the machine to set it up. You do not need to do that each time you create a service.

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

clip_image018

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

clip_image019

This is what all required to create first application. In further post I will discuss much deeper on the same. I hope this post is useful. Thanks for reading

About these ads

7 thoughts on “Creating Hello World Windows Azure Node.js Web Application

  1. Nice job Dhananjay! Just to clarify, the publishsettings file only needs to be imported once on the machine to set it up. You do not need to do that each time you create a service.

  2. Hi Glenn,

    Thanks for coming on my blog. I have updated blog with information given by you.

    Thanks
    Dhananjay Kumar

  3. Pingback: Dew Drop – January 23, 2012 (#1,248) | Alvin Ashcraft's Morning Dew

  4. Pingback: Monthly Report January 2012: Total Posts 31 « debug mode……

  5. Pingback: Windows Azure and Node.js « OpsanBlog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s