KNOWN GitHub

NPM Local Registry and debug

1. Why we should use local npm registry

  1. Decouple building from Internet. Especially in China, where connections to npm default registry ( https://registry.npmjs.org/ ) are very unstable. If our build process depends on such kind of connection, build system could be very fragile and can lead to failures more frequently.
  2. Improve download speed.

3. How to get basic information of local npm registry

  • UI (default 7002)

    http://ipaddress:7002

  • MySQL - Package versions

    mysql -u root -p
    use cnpmjs
    show tables;
    describe module;
    
    select name, version, dist_tarball from module WHERE name='bluebird' AND version='3.4.0' LIMIT 10;
    +----------+---------+--------------------------------+
    | name     | version | dist_tarball                   |
    +----------+---------+--------------------------------+
    | bluebird | 3.4.0   | /bluebird/-/bluebird-3.4.0.tgz |
    +----------+---------+--------------------------------+
    
  • Package Locations

    ~/.cnpmjs.org/nfs/

4. How to use

npm config set registry http://ipaddress:7001

5. Other Tips

  • Using local registry doesn't mean that internet can be totally disconnected

    Packages such as phantom-prebuild contains some system dependencies ( phantomjs ). Without it, npm will try to download binaries from internet.

    Other examples:

    • phantom-prebuild : need to install phantomjs manually first.

    • ffi : need to be compiled with node libraries. I'm using node 8.16.0, so https://nodejs.org/download/release/v8.16.0/node-v8.16.0-headers.tar.gz is needed.

      Download from internet and then config nodedir:

      /plugins-scripts/Dockfile

      tar -xvf /plugins-scripts/node-v6.14.3-headers.tar.gz
      npm config set nodedir /node-v6.14.3
      
    • vis-react : This package wrappers vis , and it will secretly download vis from github. Totally a disaster. Try use react-graph-vis .

  • Sync can be a long progress

    Many reasons. The first is the internet speed. The second is that all dependencies and all versions should be downloaded.

    So what if we need a package urgently?

    Try go to http://ipaddress:7002 to search and sync manually.

  • How to debug why npm fails with local registry?

    npm install --loglevel verbose

    By using this, it will print nearly all information you need. Especially steps about internet connections.




Comments !

About the blog

Some notes at work and life to share

Brian Shen