How to use npm in an environment with restricted internet access

Viewed 7382

In a restricted environment where not every user has access I would like to be able to use npm offline where ever possible.

My idea is to point the global config at a shared cache directory so that power users can do installs and the dependencies will end up in the cache directory. Other users can then do npm offline installs for anything previously in the cache.

So 2 Questions:

Will this work? Short of setting up my own local npm repository is there an easier way?

4 Answers

For build servers, a reasonable strategy is to symlink the node_modules directory against an existing directory where the modules have already been installed.

e.g. my powershell script might read something like this

If (-Not (Test-Path node_modules)) 
{
    & cmd /c mklink /d /j node_modules D:\npm-cache\node_modules
    Write-Verbose "Symlinked node_modules"
}
Related