Sometimes it might be a good idea to create a local copy of the npm repository. The following steps enable creation of such a local repository.
The npm repository uses a couchDB database. You’ll need to install couchDB 1.1.0 or higher. For installation details refer here
Specifically note the paragraph on using the new version of couchDB if you already have the earlier version installed. “CouchDB 1.1.1 can be installed on the system alongside 0.10.0. To ensure that they listen on different ports open the file /build-couchdb/build/etc/couchdb/default.ini and modify the following:”
port = 5984 to 5974
Once couchDB is up and running, we need to create our database and populate it.
curl -X PUT http://localhost:5974/registry
Next install couchapp and semver using
npm install couchapp
npm install semver
Sync the registry and search using
couchapp push registry/app.js http://localhost:5984/registry
couchapp push www/app.js http://localhost:5984/registry
To synchronize from the public npm registry to your private registry, three options are available
- Create a replication task from http://isaacs.ic.ht/registry –> local database registry via an HTTP call to ‘/_replicate like so:
curl -X POST -H “Content-Type:application/json” \
http://localhost:5984/_replicate -d \
- Through the CouchBase administrative UI
- npm install replicate -g and then
replicate http://isaacs.iriscouch.com/registry http://localhost:5974/registry.
The size of the registry is around 7.4GB with seq id 62790 after replication.
Once the registry has been replicated, with the setup so far, you can point the npm client at the registry by putting this in your ~/.npmrc file:
registry = http://localhost:5974/registry/_design/app/_rewrite
You can also set the npm registry config property like:
npm config set registry http://localhost:5984/registry/_design/app/_rewrite
or you can simple override the registry config on each call:
npm –registry http://localhost:5984/registry/_design/app/_rewrite install
To retore settings just delete the entry in the ~/.npmrc file