Everything You Need To Run Node.js Applications on Windows IIS

If you have an application that’s written in Node.JS but most comfortable with Microsoft Windows you’re in luck. Node.js runs on Windows with minimal effort, you can run an installer, and launch from a console, it’s that easy.

But if you want to run a Node.js app with other applications written in .NET or PHP through IIS you’ll need to do a few things. The process is very easy, there’s a small learning curve to getting things running just right.

Node.js on Windows - Setup, Hosting, Testing

During this process I discovered the enjoyment of Node.js and a vibrant community that takes pride in developing really well polished applications.

Getting Started With Node.js in IIS

The iisnode module, from Tomasz Janczuk does all the heavy lifting. In short the module acts as the go between IIS and Node. This enables some really nice functionality that you won’t find by running node from the command prompt exclusively.

A few of these advantages are:

– You can run a Node.js app independently on port 80.
– Your Node.js apps can be managed as part of your other websites and apps.
– Your letting IIS manage the Node.js process.

There are more “Benefits” of running node under IIS but I won’t include them because Tomasz has done an excellent job already – The Benefits Of iisnode.

What got me curious of the process was this article by Scott Hanselman – “Installing and Running node.js applications within IIS on Windows – Are you mad?”

Some of the installation instructions are a bit outdated. The process I’ve outlined in the Hostek wiki – Installing Node.js on Windows VPS, includes the latest versions.

Launching Your First Node.js App On Windows

Start with the examples provided in the iisnode folder to get a feel for how things work. Copy an example folder, and edit the web.config file according to the instructions in the wiki. Once you do this, you should be able to reach your node app in a browser.

You’ll receive output similar to:

Hello, world! [helloworld sample; iisnode version is 0.2.2, node version is v0.10.9]

What you might need to know about Node.js Apps and IIS

There’s supposed to be minimal changes required to run Node.js applications using iisnode. A few of these areas I found many people were confused by and some articles that should help you overcome the common challenges.

1. Changing the listed address of the HTTP server. Instead of defining the port as a number, you’ll use process.env.PORT environment variable. Scott Hanselman provides a code example and several references about the process.env.PORT environmental variable in the installing and running Node.js article. 

2. Rewrite url’s to let the entrypoint process all requests. You’ll want to make sure you have the IIS url rewrite module installed. Then a simple rule that sends all traffic to your entrypoint “server.js” for example should work perfectly. Here’s a great reference, with code example: http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html

3. Installing npm packages for your app. When you install Node using the .msi, you can use the “node” ready cmd environment and install any packages you require right from the command line. Navigate to your applications directory and install the necessary npm packages using the standard syntax.

npm install package

You can easily install Node.js on any of our Windows VPS’s. The example applications were deployed within our platform, using the our control panel to setup a domain. It only takes a few minutes to order a Reliable Windows VPS that you can use for production and development.

Categories: ,