Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a replica of NPM registry on an offline machine?

Tags:

So I have a need to do some new web development on a standalone box on a standalone network. This standalone network does not have any access to internet, but there are quite a few machines on it that operate in a Windows Server environment.

I have an internet-accessible machine with which I could download node and get the packages, but I need to be able to transfer the packages en masse over to the standalone machine.

What's the best way for doing that? I've read a few docs about replicating the registry on a local machine so it caches it, but how would I take that cache and port it over via usb to this standalone network?

Are there other methods for handling this?

Previously on a different project, we established our own private npm repo using Verdaccio, and published our own npm modules to that repo. I could easily set that up and then port over tar or zip files of node modules and publish them that way. But again the question is, how do I get the bulk of node packages I need?

The main thing I need to know is how to take this locally cached npm registry and set it up on a standalone machine once all the modules are copied. I can do that all on the internet box, but how would I transfer and replicate all on the server?

like image 857
Oscar McCullough Avatar asked Oct 04 '18 14:10

Oscar McCullough


1 Answers

I have the same problem.

I install and use the verdaccio and resolved my problem.

thanks to juan picado

what you need is cache properly all dependencies in your storage folder.

see here how to find it

(e.g in windows 8.1: C:\Users\xxx\AppData\Roaming\npm-cache)

You should be able to see all the resolved dependencies in the cache.

then set Environment variable with name: XDG_DATA_HOME in follow path:

  1. right click on MyComputer
  2. click properties.
  3. from left panel, click Advance system settings.
  4. from Advance Tab click Environmrnt variable ... button.
  5. in new opened from, in system variable group. click new button.
  6. enter XDG_DATA_HOME to Variable name and cache path to Variable value.
  7. click Ok button.

now, go to config.yaml and comment proxy in packages section. follow this:

packages:
  '@*/*':
    access: $all
    publish: $authenticated
    # proxy: npmjs

  '**':
    access: $all
    publish: $authenticated
    # proxy: npmjs

change registry config url.

npm config set registry http://localhost:4873/

finnally, restart verdaccio.

I hope is useful.

like image 62
AminRostami Avatar answered Nov 15 '22 00:11

AminRostami