preface

Sometimes we need to switch NPM sources during development. As NPM/YARN image source management tools, NRM and YRM can quickly switch between NPM sources to improve efficiency.

nrm

The installation

npm install -g nrm
Copy the code

use

View the list of available sources

nrm ls
Copy the code

* indicates the current source

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

Fast switching

nrm use npm
Copy the code

new

If you need to add a specific source, such as your own private source, you can do so by executing the following command, where reigstry is the source name and URL is the source path

nrm add <registry> <url>
Copy the code

As follows:

nrm add mynpm http://registry.mynpm.org/
Copy the code

delete

Reigstry for source name

nrm del <registry>
Copy the code

The test speed

nrm test npm
Copy the code

yrm

The installation

npm install -g yrm
Copy the code

use

View the list of available sources

yrm ls
Copy the code

* indicates the current source

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

Fast switching

yrm use npm
Copy the code

new

If you need to add a specific source, such as your own private source, you can do so by executing the following command, where reigstry is the source name and URL is the source path

yrm add <registry> <url>
Copy the code

As follows:

yrm add mynpm http://registry.mynpm.org/
Copy the code

delete

Reigstry for source name

yrm del <registry>
Copy the code

The test speed

yrm test npm
Copy the code

Possible problems

When we install NRM, win32 developers 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' }Copy the code

This part of the partners will find that it cannot be used after installation, the solution is as follows:

Locate the file in the corresponding path below

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

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');

Copy the code

At this point, it can be used normally

C: \ Users \ XXX > NRM - version 1.2.1Copy the code

The last

Both tools are similar, and you can use either one. NRM may have the above problems after installation, but it’s not a big deal.