Since the Microsoft Patterns and Practices symposium, I have been wanting to get started learning Node.js. So I added the JumpStart Node.js to my Safari Books Online bookshelf and installed Node.js from http://nodejs.org/.
The sample in the first chapter uses a Mongo db provider (MongoLab) but I decided to install mongo locally instead. It installed easily using the Windows Quick Start.
I was on a roll until I got to the next chapter and tried to get the modules installed. The sample uses Mocha for its unit tests. It also uses jQuery. Both proved to be a challenge to get working on my Windows 8 machine.
First issue is that Mocha requires a UNIX make command. To get this I installed Cygwin with the development tools selected as specified in this StackOverflow post. I then added the Set-Alias make “c:\cygwin\bin\make.exe” to my PowerShell profile.
That allowed the npm install mocha to succeed.
My Node.js sample uses jQuery so the next error I ran into was that jQuery install was not succeeding. It failed on the Contextify dependency. After a little goggling with Bing, I found that there are two development tools you need for Node.js development on Windows. Python 2.7 and Visual C++.
I had Python 2.7 installed but it wasn’t in the path, so that was a simple fix. If figured that the C++ dependency would be an issue since I do a bunch of C++ development. But when I ran the npm install contextify, I received.
error MSB8008: Specified platform toolset (v110) <span class="kwrd">is</span> not installed or invalid.
Please make sure that a supported PlatformToolset <span class="kwrd">value</span> <span class="kwrd">is</span> selected.
So back to StackOverflow and this helpful post pointed to the fact that if you have Visual Studio 2012 installed you need to set the VisualStudioVersion environment variable to 11.0 for MSBuild to pick the correct version. So I added $env:VisualStudioVersion=”11.0” to my default PowerShell profile and Wallah! npm install jquery succeeded.
So now I had jQuery, Mocha and Should all installed, so I typed in make test hoping for the best and no such luck.
./node_modules/.bin/mocha: line 2: dirname: command not found
./node_modules/.bin/mocha: line 4: uname: command not found
<span class="kwrd">throw</span> err;
Error: Cannot find module <span class="str">'C:\mocha\bin\mocha'</span>
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Makefile:2: recipe <span class="kwrd">for</span> target `test' failed
make: *** [test] Error 1
It couldn’t find the dirname and uname commands so it was looking in the c:\mocha\bin\mocha directory. At least this was a simple one. Adding cygwin bin to the path corrected the error and my test finally ran!
So to summarize the steps I followed to get Mocha and jQuery working on Windows 8 x64 were.
- Install Cygwin with development tools and add it to the path
- Add Set-Alias make “c:\cygwin\bin\make.exe” to my PowerShell profile.
- Install Python 2.7 and add it to the path
- Add $env:VisualStudioVersion=”11.0” to my PowerShell profile. (If you have Visual Studio 2012 installed)