Skip to content

Instantly share code, notes, and snippets.

@dandean
Last active July 14, 2018 21:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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:mysecretpassword@127.0.0.1:5984/registry

Clone npmjs.org, then:

$ npm install

Configure NPM to talk to your couch db:

$ npm config set _npmjs.org:couch=http://admin:mysecretpassword@127.0.0.1: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 git@github.com:npm/npmjs.org.git
$ cd npmjs.org
$ git remote add rvagg git@github.com: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:mysecretpassword@127.0.0.1:5984/_replicator \
    -d '{"source": "http://isaacs.iriscouch.com/registry", "target": "http://admin:mysecretpassword@127.0.0.1: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:mysecretpassword@127.0.0.1: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"
  }
@morficus
Copy link

quick correction on the curl command you mentioned above to setup the replication:

curl -H 'Content-Type: application/json' \
    -X POST http://admin:mysecretpassword@localhost:5984/_replicator \
    -d '{"source": "http://isaacs.iriscouch.com/registry", "target": "registry", "continuous": true}'

the change is that the "target" attribute is jus the name of the DB, not the full URL.

@dandean
Copy link
Author

dandean commented Jan 17, 2014

@morficus – In my case, the full url with username and password were required to avoid replication errors.

@whitingj
Copy link

For me to publish multiple versions of a module I had to add the following:

/registry/error: forbidden

"error: forbidden" is the value of the _id for the document in /registry database.

@whitingj
Copy link

For the git section I had to:

git remote update

after adding the rvag remote repo. Also I had to do this to add the remote repo:

git remote add rvagg https://github.com/rvagg/npmjs.org.git

@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