Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use npm in an environment with restricted internet access

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?

like image 627
Pablojim Avatar asked Dec 12 '13 16:12

Pablojim


People also ask

Can you use npm offline?

The method described here is to package the dependencies into a tar file, then on the isolated environment, one can use the npm install <your tar file> command to install dependencies file without internet connection.

Why cant I use npm install?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

Can you use npm without node JS?

Troubleshooting npm packagesnpm requires Node. js. If you don't have Node. js installed, we recommend you install the LTS version from the Node.


3 Answers

Per 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)

As such, npm allows you to do:

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

For example: npm install ~/Downloads/http-proxy, provided that the node_modules folder resides within http-proxy.

You could set your repository up on an internal (accessible) server and direct people to download by the same name from there.

like image 183
brandonscript Avatar answered Nov 11 '22 05:11

brandonscript


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

This acts as a mirror repository. I can give this process internet access and not other users. Then I set a environment variable for all users to point their npm repository at the sinopia instance.

Early days but this seem to be working well.

like image 44
Pablojim Avatar answered Nov 11 '22 06:11

Pablojim


r3mus is right. Though, for each user it would result in some cognitive overhead and possibly management issues.

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

like image 1
Paul Avatar answered Nov 11 '22 07:11

Paul