Node Roundup: cheerio, dbmon, HTML Sourcery

2011-11-02 00:00:00 +0000 by Alex R. Young
You can send your node modules and articles in for review through our [contact form](/contact.html) or [@dailyjs](http://twitter.com/dailyjs).


cheerio (License: MIT, npm: cheerio) by Matt Mueller is an implementation of the core of
jQuery designed specifically for server-side use. The author has removed
all of the browser support code, and created a simplified version of the
DOM designed for speed:

The goal of JSDOM is to provide an identical DOM environment as what we see in the browser. I never really needed all this, I just wanted a simple, familiar way to do HTML manipulation.\ Usage looks just like jQuery for the most part:

$('.apple').attr('id', 'favorite').html()
// Apple

Cheerio also includes a test suite, and Matt has provided instructions
on how to run them.


dbmon (License: MIT, npm: dbmon) by Francesco Strappini is an interesting library for monitoring changes to databases. Francesco's example uses postgres and the
pg module:

var pg = require('pg')
  , cli = new pg.Client('tcp://postgres@localhost/template1')
  , dbmon = require('dbmon');


var channel = dbmon.channel({
    driver: 'postgresql'
  , driverOpts: {
      postgresql: {
        cli: cli
  , table: 'testtable'
  , monitor: 'all'
  , keyfld: {
      name: 'id'
    , type: 'integer'

There's also a file system driver based on inotifywait. The
documentation includes examples on how to create generic TCP-based

HTML Sourcery

html-sourcery (License: GPL, npm: html-sourcery) by Matt Baker is a library for building HTML:

src = require('html-sourcery');

console.log(src.compile(src.doctype(5), { title: 'HTML SOURCERY', dumbledore: true }, src.html([
    src.meta({ charset: 'utf-8' }),
    src.title(function(params) { return params.title; })
    src.h1(function(params) { return params.title; }),
    src.div({ class: 'container' }, [
      src.p('A pure-Javascript library for conjuring up HTML, meant for use with node. Observe:')
// More available in the README

It reminds me of Ruby's Builder library, and the author addresses the
distinction between a templating language and a templating library:

HTML Sourcery isn't a templating language: it's a templating library, and that makes all the difference. Source files are just .js files, and you can require away at will.