Node Roundup: Shrinkwrap, Connect 2.0, ClientSide, Pretty-Data, Clusterhub, Introspect

2012-02-29 00:00:00 +0000 by Alex R. Young
You can send in your Node projects for review through our contact form or @dailyjs.


As of version 1.1.2, npm has a new feature called shrinkwrap. This allows dependencies to be locked down across the full module hierarchy. Running npm shrinkwrap will generate a npm-shrinkwrap.json file that contains the exact version of everything installed in node_modules/.

This makes deploying Node apps easier to manage, because new releases of installed modules can (and probably will) be released during development.

Dave Pacheco had some interesting things to say about how Joyent use Node as part of this feature's announcement:

It's not exactly news that Joyent is heavy on Node. Node is the heart of our SmartDataCenter (SDC) product, whose public-facing web portal, public API, Cloud Analytics, provisioning, billing, heartbeating, and other services are all implemented in Node. That's why it's so important to us to have robust components (like logging and REST) and tools for understanding production failures post mortem, profile Node apps in production, and now managing Node dependencies.

Connect 2.0

TJ Holowaychuk has announced the release of Connect 2.0 (GitHub: senchalabs / connect, License: MIT, npm: connect). The Connect documentation is now much improved, and tests have been rewritten to use Mocha.

New features include:

One major change is connect(), which replaces connect.createServer():

var connect = require('connect')
  , http = require('http')
  , https = require('https');

var app = connect()
  .use(function(req, res){
    res.end('hello world\n');

https.createServer(tlsOptions, app).listen(443);

TJ notes that previous versions of Connect used a connect.Server object that inherited from net.Server. The newer connect() method simply returns a Function, which can be used with http.createServer() or https.createServer(), thereby simplifying supporting both HTTP and HTTPS.


ClientSide (GitHub: jgallen23 / clientside, npm: clientside) by Greg Allen is a command-line tool for packaging client-side code from scripts that use CommonJS modules. It can read a package.json to determine how your library is structured.

The author is planning to write Connect middleware, and has shipped the project with thorough Mocha/Chai tests.


Pretty-Data (GitHub: vkiryukhin / pretty-data, License: MIT/GPL, npm: pretty-data) by Vadim Kiryukhin can beautify or minify JSON, CSS, and XML. Rather than using existing libraries, the author has opted to use his own regular expression-based parsing. This reduces the module's dependencies, so if you're looking for something lightweight, it might fit the bill.

The project's site also has live demos that show off the library's main features with data from sources like Yahoo! Weather and Google's minified CSS.


Clusterhub (License: MIT, npm: clusterhub) by Roly Fentanes is a bit like interprocess communication for Node:

var cluster = require('cluster')
  , numCPUs = require('os').cpus().length
  , hub = require('clusterhub');

if (cluster.isMaster) {
  // Fork workers
  for (var i = 0; i < numCPUs; i++) {

} else {
  hub.on('event', function(data) {
    // Do something with `data`

  // Emit event to all workers
  hub.emit('event', { foo: 'bar' });

Each hub has an in-memory EventVat key/value store. Roly has written some example apps, including clusterchat.

If you're looking to get more out of a CPU by running several Node processes, then this looks like a simple but potentially fast option. The author notes that the project is still experimental, but given that he's written some Mocha tests it should be relatively hackable.


Introspect (License: MIT, npm: introspect) by Kilian Ciuffolo provides Function introspection:

var introspect = require('introspect');

function fn(foo, bar, callback) {
  // function body

var arguments = introspect(fn);
// [ 'foo', 'bar', 'callback' ]

Kilian has included benchmarks, tests written with Vows, and provided instructions on how to run them.