local-npm with daemontools

Following the advice from Addy Osmani I set up local-npm on the caching proxy server. (So far, we’re caching apt, pypi and now npm.)

These examples have URLs to a machine named ‘donettes’. That is the cache. Adjust to your own network.

After setting up DNS, you need to install local-npm. The Ubuntu repo version of node is out of date, mainly because node is in flux, and the packages change. So download node from nodejs.org. They have precompiled binaries, so, that’s awesome.

You will need tools to uncompress the .xz file:

donettes$ sudo apt-get install xz-utils

Then, unxz and untar the archive. Move it into /opt, then symlink the node and npm binaries into /usr/local/bin:

donettes$ cd /usr/local/bin
donettes$ sudo ln -s /opt/node-v4.3.1-linux-x64/bin/node node
donettes$ sudo ln -s /opt/node-v4.3.1-linux-x64/lib/node_modules/npm/bin/npm-cli.js npm

Then install local-npm:

donettes$ sudo npm install local-npm -g

That’ll take a while. Then symlink it:

donettes$ cd /usr/local/bin
donettes$ sudo ln -s /opt/node-v4.3.1-linux-x64/lib/node_modules/local-npm/lib/bin.js local-npm

Then, try “sudo local-npm” to see if it works. It’ll set up databases in the directory in which it’s run. Ctrl-C to quit.

To set up daemontools, go into /etc/service, and then create the configuration:

donettes$ sudo -s
donettes# cd /etc/service
donettes# mkdir -p local-npm/log

Then create the following files. local-npm/run:

#! /bin/bash

exec local-npm --url-base http://donettes:5080


#! /bin/bash

exec multilog t ./main