Using ProgramEntryPoint element in Service Definition to use custom application as role entry point using Windows Azure SDK 1.5

Part 1: Basics of running Nodes.js from command line:

You can download node.exe from the link below:

Now lets create app.js as below:

 var http = require('http');
 
 http.createServer(function (req, res) {
 res.writeHead(200, { 'Content-Type': 'text/html' });
 res.write('<h1>Welcome. This is node.js page in Windows Azure</h1><br><br>');
 res.write('<h2>Visit <a href="https://www.microsoft.com/windowsazure/">Windows Azure</a></h2>');
 res.end();
 }).listen(8080);

Now launch nodejs server application as below:

  • C:\node-v0.4.12\bin>node app.js

After that you can open https://localhost:8080/ url with your browser to verify it NodeJS server is running:

Part 2: Using nodes.js in Windows Azure 

Now you can use the steps below to use nodes.js with Windows Azure:

  1. Create Windows Azure application with one Worker role
  2. Now you can include all of your nodes related files
    1. In this example you can just include node.exe and app.js (which you used above in Part 1)
  3. After that your can delete app.config and workerRole.cs as we are going to use ProgramEntryPoint elements released with Windows Azure SDK 1.5. Edit the following highlighted text in your Service Definition to run node.exe as worker role entry point application:
 <?xml version="1.0" encoding="utf-8"?>
 <ServiceDefinition name="AzureNodeJs15" xmlns="https://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
 <WorkerRole name="NodeJsWorkerRole" vmsize="Small">
 <Runtime executionContext="limited">
 <EntryPoint>
 <ProgramEntryPoint commandLine="node.exe app.js" setReadyOnProcessStart="true" />
 </EntryPoint>
 </Runtime>
 <Endpoints>
 <InputEndpoint name="NodeJS" protocol="tcp" port="80" />
 </Endpoints> 
 </WorkerRole>
 </ServiceDefinition>

Now you can just package your application and then deploy it to Windows Azure. 

Many thanks to Nathan for his insight in his blog: https://ntotten.com/2011/08/nodejs-on-windows-azure/