Tag Archives: node.js

Node.js on Windows Azure

Last week, I wrote about getting a node.js hello world app running on my local machine in 10 minutes. But what if you want to run node.js on Windows Azure? Turns out that takes about 10 minutes to get running as well – and you can do it from Windows or Mac … in fact, any machine that runs Chrome (or Firefox or Safari … any major browser except IE, the market leader that gets no love Winking smile).

While you can create a local environment for node.js development on Azure, the Cloud9 IDE runs in a browser. That’s a very low-friction way to get started. Eventually, you still might want to get the Visual Studio environment working, because the remote debugging features are pretty outstanding, and they require VS. But for now, just follow these instructions for creating a node.js hello world on Windows Azure.

I considered writing up a separate set of instructions, but I don’t think I could improve on these. If you have any trouble as you are following along, don’t hesitate to contact me. Remember that you can get a 90-day free trial easily, and if you are a startup you have access to a LOT of free Azure through your MSDN subscription (in fact, if you have an MSDN subscription from any source, it includes Azure benefits).

The experience is awesome – I’ve been excited about the possibility of a browser-based development environment for some time, and node.js on Cloud9 to Azure delivers. I could see building a fairly sophisticated app purely in this environment (although again, I’d probably want to take advantage of remote Visual Studio’s debugging or unit tests at some point).

The only thing I found to be slightly janky in the example is creating a new deployment … if you choose to create a new one on this screen:

create a new deployment

Then make sure you overwrite the existing deployment name that shows up on the next screen:

create a new hosted service

In future node.js post, I’ll discuss some scenarios that are good fits for node, and I’ll review javascript itself and what’s different programming server-side javascript compared to client-side.

Hello Node.js in 10 minutes

Many think that Node.js is the Next Big Thing in software development. As a way for creating web solutions, it’s got a lot going for it:

  • You write code in familiar javascript (so client and server match)
  • It uses event-driven, non-blocking I/O – which means that it’s really fast for certain types of operations and it’s easier to write certain types of applications
  • It’s open source AND it strives to support Windows as well as Linux

If you’ve been meaning to check it out, now is the time – all you need is 10 minutes to walk through this “hello world” – surely, you’ve got time for that …

Step 1: Install node.js from nodejs.org (I chose the Windows installation)

Step 2: Open cmd, add path, test node

Open a command prompt, and type

path=%path%;"c:Program Files (x86)nodejs"

To make sure that node itself is working, you can evaluate a tiny program right from the command line by typing

node -e "console.log('hey there');"

Step 3: Create, run, and test server

Of course, that’s not what node is really for – it’s really for writing web apps … so create a file called server.js and copy the following into it:

var http = require('http'); 
http.createServer(function (req, res) { 
  res.writeHead(200, {'Content-Type': 'text/plain'}); 
  res.end('Hello Worldn'); 
}).listen(1337, "127.0.0.1"); 
console.log('Server running at http://127.0.0.1:1337/');

This trivial example creates a web server listening on port 1337 of localhost that returns “Hello World” to any request. Run it by typing

node server.js

from the console and then test it by opening a web browser to http://127.0.0.1:1337/

That’s it! 10 minutes from thinking about node to running a simple “hello world” web server.

Soon I’ll get into the kinds of things node.js is good for, but first I want to show how easy it is to deploy node.js to Windows Azure – even if you don’t have a Windows machine (I’ll post that within a couple of days …)