How to use npm in a restricted internet environment

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

My idea is to specify the global configuration in the shared cache directory, so that advanced users can install the settings, and the dependencies fall into the cache directory. Other users can then perform npm stand-alone installations for anything previously in the cache.

So, 2 questions:

Will this work? Failed to configure my own local npm repository, is there an easier way?

+6
source share
4 answers

In the documentation:

npm install (with no args in a package dir) npm install <tarball file> npm install <tarball url> npm install <folder> npm install <name> [--save|--save-dev|--save-optional] npm install <name>@<tag> npm install <name>@<version> npm install <name>@<version range> npm i (with any of the previous argument usage) 

Thus, npm allows you to:

npm install /path/to/folder/containing/ node_modules

For example: npm install ~/Downloads/http-proxy if the node_modules folder is inside http-proxy .

You can install your repository on an internal (accessible) server and direct people to download with the same name.

+7
source

Thanks for answers. What I ended up using is https://github.com/rlidwka/sinopia

It acts like a mirror repository. I can give this process access to the Internet, and not to other users. Then I set the environment variable for all users to indicate their npm repository in the synopia instance.

Early days, but it seems to work well.

+2
source

r3mus is correct. Although for each user this will lead to some cognitive overhead and possibly management problems.

What could be better is to have a corporate npm repository (as described here: http://clock.co.uk/tech-blogs/how-to-create-a-private-npmjs-repository ) and then just change users (once) their registry settings using npm set registry http://yourregistry.com

+1
source

For assembly servers, a reasonable strategy is to symbolically link the node_modules directory to an existing directory in which the modules are already installed.

eg. my powershell script can 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" } 
0
source

All Articles