npmoffline: installing npm packages from the cache

npm has a feature where you can ask it to install packages from the cache, where cache-min forces npm to avoid installing packages younger than that value:


npm --cache-min 9999999 install <package-name>

This works, but I'm never going to remember that syntax, so I added an alias to my .bashrc file:


alias npmoffline="npm --cache-min 9999999 "

So now when I'm offline on a plane and want to install a package that I've already installed in the past (and so I know is in the cache), I can write this:


npmoffline install <package-I-already-installed>

and it will pull the contents from my cache.

Yayyy ?

If it doesn't work you can also list the contents of the cache with


npm cache ls

and see what packages and versions have been cached. Perhaps you can also grep it, to discard the packages you're not interested in, e.g. the following will only list entries related to node-firefox:


npm cache ls | grep node-firefox