JavaScript Library Dependencies

08 Mar 2010 | By Alex Young | Tags server nodejs narwhal

I’ve been thinking about strategies for hosting JavaScript apps. One core part of this is dependency management — it makes deployment as smooth as possible, and takes away a lot of maintenance pain. But what library dependency management options are there right now?

Require and Packages

The building block of dependency management is require. This is specified in CommonJS modules, and they have unit tests for implementors to use.

That’s not enough though. Production server-side applications need to be specific about library versions to ensure that what’s deployed is tested and safe. Yet nobody wants to waste time downloading specific versions of scripts. This is where a package manager comes in handy.

Much like there are multiple implementations of JavaScript there can be many package managers. Some programming languages opt to bundle one as standard, and others allow the community to provide and support them.

Narwhal

Narwhal has tusk, which manages virtual environments and is also a package manager. Packages use a json file to express metadata like dependencies, and can include jars, executables, C and Java source, and engines.

The package.json files look like this:

{
    "author": "Author Name",
    "contributors": [
        "Contributor Name"
    ],
    "dependencies": [
        "narwhal"
    ],
    "jars": [
        "jars/simple-4.1.10.jar"
    ],
    "version": "0.2.2"
}

Tusk usage looks like this:

alex@mog ~/narwhal[git:master]$ tusk install jack
Updating catalog.
Downloading http://github.com/280north/narwhal/raw/master/catalog-2.json
# ... etc

Tusk installs into your own path, rather than system-wide. You could use it to manage your own apps to ease deployment to production servers.

Kiwi

Kiwi is a package manager for node.js. You can install it like this:

git clone git://github.com/visionmedia/kiwi.git
cd kiwi
# sudo if required or available
sudo make install
# This installs into ~/.kiwi
kiwi -v install oo

A node app that uses kiwi looks like this:

var kiwi = require('kiwi'),
    sys = require('sys')

sys.p(kiwi.require('oo'))

Kiwi uses YAML seed files:

---
  name: OO
  description: Object-Oriented Class support
  version: 1.2.0

Kiwi has an interactive shell where you can search and install packages. Packages are fetched from a remote server, where users can register and publish their own packages. It seems like it’s still early days for Kiwi, but it’s a promising start.

I tested kiwi with the current version of node from GitHub (3947270).


blog comments powered by Disqus