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?
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.
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.
Troubleshooting npm packagesnpm requires Node. js. If you don't have Node. js installed, we recommend you install the LTS version from the Node.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With