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
- Node.js 0.6.12 is required, apparently 0.6.13 will make this easier
- NPM 1.1.8 is required – Node.js is bundled with 1.1.4 so you’ll need to run npm install npm
- Python 2.7 is required – And the python runtime needs to be on the PATH
- 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
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
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.
February 2012’s London Web Standards event at Forward London was an introduction to Node.js, the server-side javscript framework designed for high concurrency and real-time events. There were two sessions at the event, George Ornbo (@shapeshed) giving an introduction to Node, and a “Node & Tell” session, where four sets of developers came and told the gathered crowd how they’d been using Node in their work.
LWSNode - George Ornbo
Introduction to Node.js – George Ornbo
George fired up his browser, and gave the attendees the IP address of his laptop, which was running a simple Node.js chat server, which coped incredibly well with 100 people trying to join from their phones and laptops, showing how resilient it can be on a small laptop. We were then treated to a demo of a “Love/Hate” measure, taking a data feed from Twitter in real-time, it counted and displayed a graph of the percentage of love and hate on Twitter within the last 10 minutes. Seeing the data streaming in, and then the 30 lines of code used to create that was amazing. Node is a framework that does all the hard stuff for you, and enables you to write applications quickly and efficiently.
Node and Tell Sessions
Node & Tell
All of these 4 people gave it a go and were kind enough to show us what they’d been doing.
First was Maired Buchan from Head who had made a voting system based on an Arduino and Node to collect the data. Other than that the voting machine use marble runs to capture votes, she explained that they’d tried a number of places to put the Node server to get maximum performance, eventually settling on a separate server, allowing the Arduino to just count and send a message to Node. The source code is now on GitHub.
The second talk was from Andrew Nesbitt talking about the London Node User Group (which me mentioned on and off), and showing off how he’d made the LNUG website with Node and GitHub.
The third talk was Simon Thompson talking about how he’s used Node as a prototyping language, making a drag & drop filing cabinet backed by a MongoDB. He was really impressed with how simple everything was and how little setup you needed to do before everything was working.
The final talk from Daniel Knell and Jason Grant showed a responsive web app that found interesting things to do in your local area. Using Node to help them make some of the more complex geolocation calculations, the web app is a very simple idea that is well executed. It is so good that it won first place at a recent hack day, and they finished in half the time they were given.
If you want to learn more, go to LNUG.org or look into Remy Sharp’s training course, which is an excellent introduction to Node
London Web Standard crowd at Forward