I need to install a \"global\" npm applications on an offline server.
It is easy to install a normal application:
npm install
and t
Well.... after a day trying to make it work with above references (npmbox or offline-npm) came up with something way much simpler. Thanks to npmbox I have to say. The idea is the keep the cache from the instance that has online access and then use it in the one offline.
In machine with internet:
1 - clear npm cache: npm cache clear
2 - install package, lets say its x.y.z: npm install -g **package.x.y.z**
3 - copy cache in to a folder... let's call it whatever (I assume npm cache is in root folder, not absolutely sure about that):
cp -R /.npm/* **/cache-whatever-folder**
In machine with no internet:
4 - take this cache-whatever-folder to the instance with no internet and after that, clean cache and install with it (I won't indicate how to copy the folder :)
npm cache clear
npm install --global --cache **/cache-whatever-folder** --optional --cache-min 99999999999 --shrinkwrap false **package.x.y.z**
Done
List the dependencies in bundledDependencies
in your package.json, and then run npm pack
to create a tarball. Get that over to the other machine, and either npm install <tarball>
, or just crack it open manually.
https://github.com/npm/npm/issues/1349
npmbox is outdated
Use npm pack
command (npm docs), no need to install anything.
If you want only one package (for example, forever
), you can run:
npm pack forever
this command will fetch it to the cache, and then copy the tarball to the current working directory as -.tgz
Then, from the folder you created the package, you install it with:
npm install -g ./forever-x.y.z.tgz
If you want a whole project to be installed offline, include a poperty in your package.json
named bundleDependencies
and list all dependecies you need in this field.
// package.json
"dependencies": {
"archiver": "^2.1.1",
"axios": "^0.16.2",
"body-parser": "^1.18.3"
},
"bundleDependencies": {
"archiver": "^2.1.1",
"axios": "^0.16.2",
"body-parser": "^1.18.3"
}
Then run npm pack
.
It will create a .tgz
file of your whole project and dependencias.
You just have to copy it to the offline server and untar.
Try npmzip
npm install -g npmzip
npmzip <package>
You will get the tarball in the current directory This may be moved to the target machine and :
npmunzip <tarball>