Node is great, NPM may be even greater. But would not it be awesome to have your own repository/mirror, so you will not be dependent on the public repository?

Let’s take a look at your options:

The old-school way

This setup is like how NPM was a few years back and uses the same stack. For this, you will need:

  • CouchDB
  • Node.js server

After you have the prerequisites, what you have to do is configure the CouchDB to sync from the official public repository.

After it is finished, you only have to deploy npmjs, which means cloning from git, and make some configuration.

With a proxy

Yammer created a lazy NPM mirror which caches the responses from the official registry. For this, you will need:

  • nginx

After you have a functioning nginx proxy, a cache zone must be set:

 # this is the npm zone, things stay active for 3 days
proxy_cache_path /var/cache/npm/data levels=1:2 keys_zone=npm:20m max_size=1000m inactive=3d;
proxy_temp_path /var/cache/npm/tmp;

Then site configuration have to be added to:

server {
 listen 80;
  location / {
  proxy_cache npm;
  proxy_cache_valid 200 302 3d;
  proxy_cache_valid 404 1m;
  sub_filter '' '';
  sub_filter_once off;
  sub_filter_types application/json;

That’s it, you should be good to go.

With Sinopia

Sinopia is a private/caching npm repository server. For Sinopia you do not need any database, only Node.js — it uses file system as storage.

After installing and launching it, it is good to go. Another great thing about Sinopia is that it has a Chef cookbook:

More info:

With cnpmjs

Private npm registry and web for Enterprise” — at least this is what cnpmjs states. It uses MySQL, and Simple Store Service. Also, cnpm is written using Koa, which uses the new ES6 generators — to run this, you will need at least Node.js version 0.11. This is the system that powers the Chinese NPM mirror.

More info and installation:

So far so nice. Would not it be awesome to easily switch between the public repository and yours?

As of 23th May (2014) npm supports per-project .npmrc files.

When working locally in a project, a .npmrc file in the root of the project (ie, a sibling of node_modules and package.json) will set config values specific to this project.

Note that this only applies to the root of the project that you're running npm in. It has no effect when your module is published. For example, you can't publish a module that forces itself to install globally, or in a different location.

More on .npmrc at: