NRM and yrm, NPM source manager, can quickly switch between sources

Time:2021-9-22

preface

When developing, we sometimes need to switch NPM sources.nrmandyrmAs the image source management tool of NPM / yarn, it can quickly switch between NPM sources and improve our efficiency.

nrm

install

npm install -g nrm

use

View a list of available sources

nrm ls

Where * is the currently used source

  npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/

Fast switching

nrm use npm

newly added

If we need to add a specific source, such as our own private source, we can execute the following command to add it, where
reigstryIs the source name,urlPath to source

nrm add <registry> <url>

As follows:

nrm add mynpm http://registry.mynpm.org/

delete

reigstryIs the source name

nrm del <registry>

Test speed

nrm test npm

yrm

install

npm install -g yrm

use

View a list of available sources

yrm ls

Where * is the currently used source

  npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/

Fast switching

yrm use npm

newly added

If we need to add a specific source, such as our own private source, we can execute the following command to add it, where
reigstryIs the source name,urlPath to source

yrm add <registry> <url>

As follows:

yrm add mynpm http://registry.mynpm.org/

delete

reigstryIs the source name

yrm del <registry>

Test speed

yrm test npm

Possible problems

When we installnrmAfter,win32Developers may have the following problems:

C:\Users\xxx>nrm -v
internal/validators.js:124
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

[TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
  at validateString (internal/validators.js:124:11)
  at Object.join (path.js:375:7)
  at Object.<anonymous> (C:\Users\xxx\AppData\Roaming\npm\node_modules\nrm\cli.js:17:20)
  at Module._compile (internal/modules/cjs/loader.js:1063:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
  at Module.load (internal/modules/cjs/loader.js:928:32)
  at Function.Module._load (internal/modules/cjs/loader.js:769:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  at internal/main/run_main_module.js:17:47
] {
  code: 'ERR_INVALID_ARG_TYPE'
}

These small partners will find that they can’t be used after installation. The solutions are as follows:

Find the file with the corresponding path below

C:\Users\xxx\AppData\Roaming\npm\node_modules\nrm\cli.js:17:20

Modify line 17 of cli.js

//const NRMRC = path.join(process.env.HOME, '.nrmrc'); 
const NRMRC = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], '.nrmrc');

Then it can be used normally

C:\Users\xxx>nrm --version
1.2.1

last

These two tools are similar. Either one is OK. NRM may have the above problems after installation, but the problem is not big.