local-npm is a Node server that acts as a local npm registry. It serves modules, caches them, and updates them whenever they change.

Last weekend I was on a plane flying to Lisbon and sometimes its handy to have a local cache of npm packages. This could be being on a flight or during a workshop. Getting this working is pretty simple.

local-npm

Using local-npm is like using a local npm mirror without a complete replication. It's not as big as sinopia where you can also have private repo's.

Your npm installs are fetched from npmjs and then modules and their deps are stored in a local PouchDB. It also takes care of keeping modules updated when they change.

To get local-npm installed, run:

# npm install -g local-npm
# local-npm

local-npm replicates the skimdb part of the database and start replicating. You don't have to wait for it to be at 100%, you can already start using the registry. It will fallback to the online version for any library that isn't in it's proxy yet.

To complete setup, you need to set npm to point to the local server local-npm:

# npm set registry http://127.0.0.1:5080

The local-npm's server setup also has a simple UI for browsing cached modules and searching for them. You can access this at http://localhost:5080/_browse.

npmrc

Switch between different .npmrc files with ease and grace

It's handy to have a local proxy, but sometimes its easier to just use a live one or use the private repo from work.
If that's the case you know it's annoying to do the switching between a bunch of different .npmrc files and manually managing symlinks.

npmrc is a handy tool to save the day. It will switch your .npmrc with a specific named version.

Installation:

# npm install -g npmrc

First time you run it, it will create the links:

# npmrc
Initialising npmrc...
Creating /Users/leon/.npmrcs
Making /Users/leon/.npmrc the default npmrc file
Activating .npmrc "default" 

Lets create the local-proxy profile:

# npmrc -c local-proxy
Removing old .npmrc (default)
Activating .npmrc "proxy"

A blank profile will be created. To point your profile to the local registry and start using it:

# npm set registry http://127.0.0.1:5080

and switching back to the default is as simple as just using the alias:

# npmrc default

It also has some nice generic npmjs repos as an alias:

# npmrc -r eu
Using http://registry.npmjs.eu/ registry.
For more options check the help.

date: 24 March 2016