Skip to content

Instantly share code, notes, and snippets.

@dandean
Last active July 14, 2018 21:31
Show Gist options
  • Save dandean/8365028 to your computer and use it in GitHub Desktop.
Save dandean/8365028 to your computer and use it in GitHub Desktop.
How I got the npmjs.org registry running on my mac.

Install CouchDB (1.5)

$ brew install couchdb

It may throw an exception while compiling erlang. If so, you need to install a different gcc, reinstall erlang, then try the couchdb install again:

$ brew install apple-gcc42
$ brew reinstall -v --use-gcc erlang
> Took a REALLY long time
$ brew install couchdb

Add required ini configurations:

$ subl /usr/local/etc/couchdb/local.ini

[httpd]
secure_rewrites = false

[ssl]
verify_ssl_certificates = false
ssl_certificate_max_depth = 1

[admin]
admin = mysecretpassword

Start CouchDB (new terminal session, probably)

$ couchdb

Open Futon and sign in as the Admin:

http://127.0.0.1:5984/_utils/

Create the NPM Registry Database:

$ curl -X PUT http://admin:[email protected]:5984/registry

Clone npmjs.org, then:

$ npm install

Configure NPM to talk to your couch db:

$ npm config set _npmjs.org:couch=http://admin:[email protected]:5984/registry

Install and Build the npmjs.org Couch App

At present, the mainline repository and instructions do not work. We need to instead use the code from a repository that does work.

Clone npmjs.org, add the correct remote and checkout the correct branch from the remote:

$ git clone [email protected]:npm/npmjs.org.git
$ cd npmjs.org
$ git remote add rvagg [email protected]:rvagg/npmjs.org.git
$ git checkout -t rvagg/new-install-docs

Now that we've got the code, we need to install its dependencies and load it into couchdb:

$ npm install
$ npm start
$ npm run load

Fix the next command (npm run copy) before running. Open copy.sh. It is not properly passing the auth username to curl. Change the last command from:

$ curl -k $auth "$url/_design/scratch" \
  -X COPY \
  -H destination:'_design/app'$rev

to:

curl -k -u admin "$url/_design/scratch" \
  -X COPY \
  -H destination:'_design/app'$rev

Then run it:

$ npm run copy

Start Replication:

From FUTON:

From the command line

$ curl -H 'Content-Type: application/json' \
    -X POST http://admin:[email protected]:5984/_replicator \
    -d '{"source": "http://isaacs.iriscouch.com/registry", "target": "http://admin:[email protected]:5984/registry"}'
> {"ok":true,"id":"e25d8c28e6356ef15909fa251700185e","rev":"1-73efd11a1223fe69dc8652fb8ac03a0a"}

To cancel the previous replication, DELETE the item in the _replicator database using the document id and rev:

$ curl -H 'Content-Type: application/json' \
    -X DELETE http://admin:[email protected]:5984/_replicator/e25d8c28e6356ef15909fa251700185e?rev=1-73efd11a1223fe69dc8652fb8ac03a0a
> {"ok":true,"id":"...","rev":"..."}

Configure npm to speak to local registry (note the lack of user:pass):

$ npm config set registry http://127.0.0.1:5984/registry/_design/app/_rewrite

Test that this works by performing a search:

$ npm search dean

Add your npm user to the users database. This should match the user you have configured on the main NPM registry

$ npm adduser

Publishing to the private registry:

Add this to any private package.json:

  "publishConfig":{
    "registry":"http://127.0.0.1:5984/registry/_design/app/_rewrite"
  }
@whitingj
Copy link

I didn't replicate from the public repository which is why I had to add the "error: forbidden" document. The other thing I had to do was setup replication from the _users database to the public_users database. Adding those 2 things seems to have given me a working registry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment