I’ve been dabbling a bit recently in writing native extensions for node.js, specifically, I wanted to use exiv2 from within Node. Exiv2 is a fantasic tool for reading and writing Exif (and IPCT/XMP) metadata to/from photos, see Wikipedia or exif.org for more info. The ability to manipulate Exif data in my photos is just a small part of a bigger pet project I’ve been working on, which uses Node..
Rather than launch the exiv2 process from within Node (messy), I had a go at writing a native C++ extension that would use the exiv2 library to do the reading/writing. Additionally, this processing happens on a background thread, so its asynchronous when used from within Node itself (in keeping with the non-blocking Node way of doing things).
I also learned quite a lot about Node & V8 in the process, the ability to add easily add asynchronous extensions like this is a really awesome feature of Node. Some links I found useful for developing native Node extensions:
- CloudKick have an excellent tutorial
- V8 Embedders Guide
- V8 Cookbook
- The source code for Node itself is a good reference for how to use V8