Articles Tagged ‘Node.js’

Installing JSDom on Windows

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.

Node & Tell at London Web Standards #lwsnode

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 is a front-end javascript developer who wanted a simpler way to create web apps quickly, and in a language that he knows. Enter Node.js, with its “Event driven I/O”, or better put as “Network programming with javascript”.

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.

George then explained why it was so fast – Node works on an event loop, rather than threads. The idea is that no operation should be blocking so that Node can always keep getting http requests and fire of requests to the database or any other data sources asyncronously. It’s a big of a head scratcher to anyone who hasn’t done much high-performance javascript before, but it’s a very efficient way to program. George showed two graphs (roughly transcribed to the notes) on node performance vs apache for high concurrency and memory usage: node wipes the floor with it. Note: since this talk took place, Apache 2.4 has come out. These graphs are a bit different now but Ngix is still well ahead on speed

In summary, Node is great for high concurrency situations and for making server back-ends quickly. It’s a break from your normal programming style but is is just JavaScript when you’re over that hurdle. Give it a go!

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.

Node Training

If you want to learn more, go to or look into Remy Sharp’s training course, which is an excellent introduction to Node

London Web Standard crowd at Forward

London Web Standard crowd at Forward