Setting up Node on Windows

There is a lot of fuss at the moment in the web development community about a framework called Node.js that allows you to run JavaScript server side. A number of claims about fantastic scalability and lack of locking have been made regarding Node – whether these are actually true and if the advantages outweigh the disadvantages is another question..

Let’s assume however you are a Windows user who wants to see what all the fuss is about and get up and running with Node.js..

Previously getting Node.js running on Windows was a little painful and involved some manual compilation, patching of libaries and an application called Cygwin that emulated a *nix environment.

But no more! getting Node.js running on Windows is now very easy and it can be hosted within IIS by installing IISNode. This is actually pretty important as allows you to take advantage of a number of IIS features thus answering the question of how Node should be managed/hosted on a Windows machine. It’s worth noting as well that Node.js is even supported on Windows Azure.

Below are instructions on how to install Node.js on Windows:

First you are going to need a Windows OS that is at least as new as Vista with the IIS URL Rewriter module installed (add/remove programs).

If this is all good then go download & install Node.js from http://nodejs.org/. At the time of writing the most recent version is held at: http://nodejs.org/dist/v0.6.10/node-v0.6.10.ms.

Next you want to get hold of IIS Node by going to https://github.com/tjanczuk/iisnode.

IIS node has its own installer at (src/setup/iisnode-msi/) run the installer. Once you have run the IIS node installer if you look under the Modules section in IIS you will see a new module has been created:

New Node module in IIS

The next step is to create a directory for your node application (note you can also incorporate a node endpoint into an existing application by adding an entry to web.config but let’s keep it simple).

Create a site or application to map through to this directory in IIS (to create an application right click on default website and select Add Application). I am calling my virtual directory AlexNode.

Now create 2 files within your directory:

  • test.js
  • web.config

Open test.js up in a text editor and enter the following hello world node code (this is from the IISNode example):

var http = require(‘http’);

http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/html’});
res.end(‘Hello, world! [helloworld sample; iisnode version is ‘
+ process.env.IISNODE_VERSION + ‘, node version is ‘ + process.version + ‘]’);
}).listen(process.env.PORT);

In web.config enter the following to tell ASP.net to use the Node module we have just installed:

<configuration>
<system.webServer>

<handlers>
<add name=”iisnode” path=”test.js” verb=”*” modules=”iisnode” />
</handlers>

</system.webServer>
</configuration>

That’s it you should now be able to view the node server running on your site by going to an address similar to the following:

http://localhost/alexNode/test.js

My site displays the following text:

Hello, world! [helloworld sample; iisnode version is 0.1.14, node version is v0.6.9]

That’s the set-up basics – there are heaps of extension libraries for Node that you should check out at http://search.npmjs.org/ and IISNode contains several samples that can be installed by going to: %programfiles%\iisnode\setupsamples.bat

Next why would you actually want to do this? 🙂

 
 

 

 

Advertisements

4 thoughts on “Setting up Node on Windows

  1. Thanks, instructions worked fine for me on windows 7 x64. One thing, if you copy the test.js and web.config text off this page, make sure the ” and ‘ characters copy properly or you’ll have issues.

  2. Thanks Alex, Spent a few hours trying to get set up for node on windows. Tried and failed on a couple of different samples/tutorials.

    Got yours to run. Simple is most definitely best!

Comments are closed.