Friday, November 1, 2013

How to install Node.js on Windows and integrate with IIS

I've decided that it's time for me to look at using node.js on Windows because I want a JSON web service that will run inside IIS, using SQL Server and I've learned that node.js is now a first-class citizen on Microsoft platforms.

My goal is to develop a web service that can consume my SQL Server DBs natively and run inside IIS using Node.js for [theoretically] maximum performance.

My development platform (where I'll first run all these steps) is Windows 8.1 but as I understand it, this should all work from Windows 7 to 8.1 with virtually no differences. At this time, I'm using WPI 4.6.

This process will give you an environment where IIS uses url-rewrite to send all requests to server.js in the project folder and it will do the routing and then web.config uses the iisnode section to cause certain files/folders to get processed through node so that IIS is the web server and node is essentially the application processor.

The first step is to install Web Platform Installer (WPI). At present, this can be found at:

WPI is essentially an IIS package manager but it does a LOT more than just manage packages. Using WPI, we will install WebMatrix which does even more than WPI (setup entire sites, with dependencies and provide a simplistic (yet still powerful) development tool that can then publish an entire site (with dependencies) to IIS AND run locally for development.

WPI is a 114KB download (web installer itself) that takes just a couple minutes to install and run.

First run will look something like the following except you may see newer packages (they're listed newest to oldest by default):

The next step is to simply use WPI to install WebMatrix. In reality, you can install WebMatrix directly (though I think that might install WPI anyway), but WPI is akin to NPM and you'll likely want it soon anyway.

At the top-right of WPI, in the search box, type "WebMatrix" and press enter/return. Find the latest version (currently 3) then click the "Add" button for it. Next, hit the "Install" button at the bottom.

I have a fairly fast connection (150Mb Cox Ultimate) and a fast machine so my install took about 20 seconds. When the install is complete, exit WPI and launch "Microsoft WebMatrix" from your Start Menu (or MetroUI if you've managed to live with it. I use StarDock's Start8 to give me back my start menu to and basically do away with metroUI).

Once you've launched WebMatrix (here-unto referred to as WM), deal with the Azure marketing content (I hit "not now" at the bottom right) and you're ready to setup a Node.js site.

Click the big "New" icon then "Template Gallery".

On the left, select "Node.js" template group then pick one of the templates. I'm using "Starter Site" for this tutorial. Next provide a "Site Name" at the bottom then click "Next".

As you click "Next" on the next few screens, the "magic" happens. ALL the dependencies are identified, downloaded, installed and configured rather than you having to locate all the compatible libraries, apps, modules, etc.. Just click "I accept" and sit back with WebMatrix does all the hard work. This will also install NPM by the way :)

This process will install "IISNode for Express" by default. If you are running full IIS (real development machine or server), you can now go back into WPI and search for and add "IISNode" to install the version for IIS, otherwise you now have a fully working Node.JS site ready to be opened in Visual Studio, run locally as-is, or published to an IIS Server.


If you're running full IIS locally and want to deploy locally (or on a machine with IIS), then follow the steps below (found them HERE). Also, using WPI, install "IISNode for IIS (IIS exists)".

Here is the quick version of what I found that is more recent guidance and was enough for my demo:
  1. 1.Install Web Deploy 3.5 for Hosting Servers [using WPI]
  2. 2.Bounce IIS and IIS Manager [Restart IIS]
  3. 3.Configure the Management Service I used parts of this:
  4. 4.Install Web Matrix to another machine. (You cannot deploy to the local machine.) [Yes you can, you just can't deploy to 'localhost', you must use your machines FQDN]
  5. 5.Deploy from the machine in 4 to the machine configured in 3. [Which can be the same]
Hope that helps others through the process
I still had some issues afterwards and one was resolved by opening "Programs and Features" from the control panel, searching for "Web Deploy", then click "Change" and select the deselected options (like the IIS extension).


Of course, after taking the time to put this post together, while searching for Razor related content, I ran across the following (which is basically my post with follow-up related to Node.js code):


Nemco said...

It is a great sharing...I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. I enjoyed every little bit part of it.
node.js development services

Post a Comment