Steve Workman's Blog

Installing JSDom on Windows

Posted on by Steve Workman About 2 min reading time

If you've ever wanted to scrape a web page and extract some information using Node.js, there's a really useful module called JSDom that parses a document and gives you a DOM that you can then manipulate with YUI or jQuery.

This all works really well... on Linux and OS X. On Windows, Node.js can't run pre-built native Node.js libraries, so it has to be build by the NPM build service. This is all documented on the JSDom github issue, but for brevity, this is what you have to do to make it work

  1. Node.js 0.6.12 is required, apparently 0.6.13 will make this easier
  2. NPM 1.1.8 is required - Node.js is bundled with 1.1.4 so you'll need to run npm install npm
  3. Python 2.7 is required - And the python runtime needs to be on the PATH
  4. Microsoft Visual C++ 2010 is also required - I've got the whole Visual Studio installed on my machine, but I think you'll be able to get away with the distributable package
  5. I believe you'll also need the node-gyp module installed globally Node-gyp is included in NPM

**Update: **Node.js 0.6.13 is now out with npm 1.1.9 and an updated node-gyp which will make this a lot easier. However, you'll still need Python 2.7 and Visual C++ 2010

Update 2: Having the Visual C++ redist package isn't enough, you have to have Visual Studio installed too. You can get the express edition for free from Microsoft here

**Update 3: **The express edition of Visual C++ 2010 doesn't come with the latest SDKs so it won't compile out of the box. You'll need to run Windows Update and download a special set of compiler updates from Microsoft. Thanks to Pavel Kuchera for finding this one out (the hard way).

That's a lot of dependencies, but it should all work. Once Python and C++ are installed,  the commands you'll need to run are:

npm install -g npm

npm install -g node-gyp

npm install jsdom

And that's it. If there are build errors, let me or the JSDom team know.