Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Guide to setting up a local NPM registry

CouchDB

Install CouchDB. This guide assumes 1.3.1. Set up an admin account.

Create the database required by NPM:

curl -X PUT http://admin:password@127.0.0.1:5984/registry

Then edit the local.ini config to add:

[vhosts]
registry.npm:5984 = /registry/_design/app/_rewrite

[httpd]
secure_rewrites = false

Restart CouchDB after editing its config, and make sure to add registry.npm to your hosts file (or similar).

npmjs.org

Clone https://github.com/isaacs/npmjs.org then cd into the directory. Run npm install semver couchapp.

npmrc

We want a custom NPM config file to prevent interference with regular https://npmjs.org. Call it ~/.localnpmrc and add the following:

registry = http://registry.npm:5984/
npmjs.org:couch = http://admin:password@127.0.0.1:5984/registry

Then alias NPM so it uses your new config:

alias localnpm='npm --userconfig=/full/path/to/.localnpmrc'

Actual setup

In the npmjs.org checkout:

localnpm run start
localnpm run load

If this is an initial setup:

curl -k -u admin:password http://127.0.0.1:5984/registry/_design/scratch -X COPY -H destination:_design/app

Or if you're updating a previous registry:

localnpm run copy

Create the following document in the registry database:

{
   "_id": "error: forbidden",
   "forbidden": "must supply latest _rev to update existing package"
}

Without this document you can't publish newer versions of existing packages.

Using NPM

Use adduser to create your user account.

When publishing a package, make sure the following is in its package.json:

"publishConfig": {
  "registry": "http://registry.npm:5984"
}

To add other users as maintainers of your package your user account must be able to view the _users document of those other users. E.g. in the security settings for the _users database add your username under Admin Names.

@ab077u

This comment has been minimized.

Copy link

@ab077u ab077u commented Mar 4, 2020

https://verdaccio.org/ could be an off-the-shelf alternative. Since the above seems to be bit outdated.

@novemberborn

This comment has been minimized.

Copy link
Owner Author

@novemberborn novemberborn commented Mar 4, 2020

Yea, it's 7 years old!

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