primers

With the development of the front section, node front-end engineering has become a standard daily work. NPM is used to manage the packages that Node relies on. NPM is very difficult to use in China, you can understand the specific reasons. So there are all kinds of powers that solve these problems. Nothing more than the following schemes.

1. Climbing a wall with a ladder: This method requires buying a ladder and is risky.

2. CNPM: This method is to use CNPM command to point the installed package to Taobao NPM image library, download the software package will be much faster. But there are drawbacks. Only when using CNPM to install NPM packages will point to taobao image, many NPM packages themselves rely on many other packages, and integrated with NPM install, when installing a package dependency package, will also use NPM install!! This leads to installing a package using CNPM, but errors are reported halfway through. Is it sour?

The solution

Isn’t there a better solution? B: of course! The ultimate solution is to change the repository source of the NPM command to a domestic one, so that when a package uses the NPM command to install dependencies, it still accesses the domestic image. This ensures that the installation will not fail due to network problems, but it also has the disadvantage of not being able to publish after switching to the domestic source, because the domestic source is only a copy library and cannot be committed. But there is no publish for just using and installing packages.

Specific implementation

Here you’ll need a package called NRM, which is the NPM resource manager that allows you to quickly switch between NPM sources.

1. Install NPM install NRM -g. After the installation is successful, enter NRM help to view the help information.

2. Run NRM ls to view all sources. Preceded by an asterisk is the current source in use.

nrm ls * npm ----- https://registry.npmjs.org/ cnpm ---- http://r.cnpmjs.org/ taobao -- https://registry.npm.taobao.org/  nj ------ https://registry.nodejitsu.com/ rednpm -- http://registry.mirror.cqupt.edu.cn skimdb -- https://skimdb.npmjs.com/registryCopy the code

3. Run NRM use Taobao to switch to the Taobao source and enter NRM ls to view the current source.

nrm use taobao
Registry has been set to: https://registry.npm.taobao.org/
Copy the code

nrm use npm

Download jquery and try it out. npm install jquery