Skip to content

Instantly share code, notes, and snippets.

@Qwerios
Last active January 22, 2018 17:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qwerios/11371459 to your computer and use it in GitHub Desktop.
Save Qwerios/11371459 to your computer and use it in GitHub Desktop.
Setting up private NPM repository

Official npm mirror

The main idea is to make an official NPM mirror as detailed here: https://github.com/npm/npm-registry-couchapp

Unfortunately the above instructions appear to be flawed and didn't working for me. Thankfully someone has taken the time to create an updated set of installation instructions: https://github.com/rvagg/npmjs.org/tree/new-install-docs

Bug with updated instructions

Only one problem remains with the above instructions and that is the credentials for the copy script. In copy.sh you need to fix the credentials for curl. Change this (line 46):

-curl -k ${auth:+-u "$auth"} "$url/_design/scratch" \

to this:

curl -k -u admin "$url/_design/scratch" \

Where 'admin' is the name of the administrator account you chose for your Apache CouchDB. You will be then be prompted for the password.

CouchDB and replication

I used version 1.5.0 for my installation. I immediately fixed admin party mode and used the credentials during the installation.

To setup replication that will persist beyond reboots I created a document in the _replicator database using the following curl script:

curl -H 'Content-Type: application/json' \
    -X POST http://admin:secret@127.0.0.1:5984/_replicator \
    -d '{"id": "npmjs", "source": "https://skimdb.npmjs.com/registry", "target": "http://admin:secret@127.0.0.1:5984/registry","continuous":true}'

Don't forget to replace your username/password in the above curl script. I chose to use the light replication (skimdb) and I am only syncing module data and not the attachments. Change the source url as desired.

Using your repository

As detailed in both the offical and updated instructions above you can now set your registry value in ~/.npmrc to:

registry = http://yourserver:5984/registry/_design/app/_rewrite

If you're working with multiple repositories I recommend installing nmprc to easily switch between profiles:

npm install -g npmrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment