Npm Taobao mirror cnpm installation and use (latest version), cnpm temporary single/permanent use

foreword

npmFull name Node Package Manager, is node.jsa module dependency management tool. Since npmthe source of the website is abroad, it is inconvenient for domestic users to use it, and there may be problems such as inaccessibility, abnormality, or slow downloading. To this end, Taobao built cnpm (the client of China's npm mirror), which is a complete npmjs.org mirror, which you can use instead of the official version. The following introduces the commonly used npm mirror resources in China—
various usage methods of Taobao mirror (Permanent/Single)

Note : http://npm.taobao.organd http://registry.npm.taobao.orghas officially gone offline and stopped DNS resolution on 2022.06.30.
The new domain name is npmmirror.com
domain name switching rules:

  • http://npm.taobao.org => http://npmmirror.com
  • http://registry.npm.taobao.org=>http://registry.npmmirror.com

The following are the latest version of the usage method, please rest assured to eat! !

Example of how to use Taobao Mirror

Premise: Node is installed on the computer , and the following command is entered in cmd

1. Single temporary use

  • For example, my current project npm installis too slow to install all module dependencies, but I don’t want to install the whole cnpm. At this time, I can replace the source with Taobao image, which will be much faster.
npm install --registry=http://registry.npmmirror.com
  • Similarly, if you just want to install a module module with a mirror image, you can use the following command
npm  install 模块名 --registry=http://registry.npmmirror.com
  • For example, I want to install express with Taobao image
npm  install express --registry=http://registry.npmmirror.com

--registry https://registry.npm.taobao.orgIt can be placed before and after the install

2. Use cnpm

  • Use the cnpm command line tool customized by Ali to replace the default npm, and enter the following code
 npm install -g cnpm --registry=http://registry.npmmirror.com
  • Check if the installation was successful:
cnpm -v
  • After the installation is successful, the way to install dependent packages in the future is the same as that of npm, except that the npm command can be replaced with cnpm, for example:
cnpm install express

In the future, you can install it with npm or cnpm

3. Permanently replace the npm source with cnpm

When developing react-native, do not use cnpm. The module path installed by cnpm is strange, and the package cannot be recognized normally.
Therefore, in order to facilitate development, we'd better use Taobao's mirror source directly and permanently

  • Direct command-line settings
npm config set registry http://registry.npmmirror.com
  • Modify settings manually
  1. Open .npmrc文件( C:\Program Files\nodejs\node_modules\npm\npmrc, if not, you can use the git command line to build one ( touch .npmrc), use the cmd command to build an error)
  2. registry=http://registry.npmmirror.comJust add .
    If you need to restore to the original official address, you only need to execute the following command:
npm config set registry https://registry.npmjs.org
  • Check whether the installation is successful:
 npm config get registry

will return http://registry.npmmirror.com

Partial reference from: https://aqingya.cn/articl/c8d8dd8.html#npm-%E6%B7%98%E5%AE%9D%E9%95%9C%E5%83%8F%E7%9A%84 %E5%AE%89%E8%A3%85

Guess you like

Origin blog.csdn.net/qq_23073811/article/details/127904378