Nilo Paim
Nilo Paim

Reputation: 447

Unable to install Socket.IO disconnected from internet

I need to install Socket.io on a machine without internet access.

I've downloaded Node.js and Socket.IO on another box, but when I copy and try to install them on the isolated machine, Node.js installs ok, but Socket.IO insists on connect to GitHub.

How can I install Socket.IO without an internet connection? Should I install all dependencies offline? If so, what are the dependencies of Socket.IO?

Upvotes: 3

Views: 344

Answers (1)

Lee Jenkins
Lee Jenkins

Reputation: 2470

It turns out that npm supports package caching. Basically you create a cache on the development machine that does have internet access, copy that cache onto your target at the same time that you install your nodejs application, and then install the packages from the cache. I assume from your question that the target machine already has nodejs and npm installed.

Step 1. Use npm to create a cache directory on your development machine

First, create a cache directory and configure npm to use it. Then install each of your packages.

mkdir                ../my-cache
npm config set cache ../my-cache
npm install --save [email protected]
npm install --save [email protected]
etc.

If you look in the my-cache directory you'll see sub-directories for each installed package.

Step 2. Copy the cache to your target machine along with your node application

No rocket science here: make sure you copy the my-cache directory to your target machine.

Step 3. Use npm to install the packages from the cache

Configure npm to use the cache directory. Be aware that npm will still try to go fetch the package files form the internet. And it will retry after a failure. I found a couple recommendations for forcing npm to use the cache, but those options did not work. But I did find a way to significantly reduce the amount of time npm spends trying to fetch before looking in the cache.

npm config set cache ../my-cache
npm config set fetch-retries 1
npm config set fetch-retry-maxtimeout 1
npm config set fetch-retry-mintimeout 1
npm install [email protected]
npm install [email protected]

Be aware that you cannot just type npm install because npm will not use the cache. This is a bit of a pain. If you want a robust install you can write a tiny nodejs app to parse out the dependencies and calls child_process.exec to install each one.


(*) I should mention that there is a package called npm-cache (https://www.npmjs.com/package/npm-cache). In my case npm-cache did not suit my needs. But you may be able to make it work for you.

Upvotes: 2

Related Questions