npm without internet
Published on 07-07-2015
2 min read
It's easy to run npm to install packages even on a system without internet access, or behind a corporate firewall. First note that npm has proxy settings, so if you have access to the correct credentials, try that first.
Let's assume you're developing a web application and you use Grunt for managing jshint and uglify tasks. This requires the npm package grunt-cli to be installed globally. All the other packages (i.e. jshint and uglify) can be run locally, so it's sufficient to copy node_modules with these packages from another installation.
Assuming you have another system with internet access/no proxy, and you have a working project with all the packages there:
- Zip the node_modules in the project dir to e.g. node_modules.zip.
- Go to %userprofile%\AppData\Roaming\npm\node_modules\grunt-cli\
npm packthis should result in a grunt-cli-x.y.z.tgz
- Collect the node_modules.zip, grunt-cli-x.y.z.tgz and Node.js installer and place them on the target system (e.g. by local network or usb drive).
- Prepare the project dir on the target system, e.g. from a Git repo on the network or from scratch. The Gruntfile.js and package.json should already be in the root of the project.
- Install Node.js on the target system. This should also install npm. Check this with
- Unpack the node_modules.zip into the project dir, such that <project>/node_modules contains e.g. grunt-contrib-jshint.
- Place grunt-cli-x.y.z.tgz in some temporary dir, e.g. \tmp and run
npm i -g grunt-cli-x.y.z.tgz.
- Grunt should now be installed globally, try
- Now it should be possible to run
gruntin the project dir.
If you want to do a lot of offline installations, you might want to +1 this issue. It explains the process of doing several pack and install steps and how this could be simplified by extending the pack feature to also zip all the depencies of a package.