This article describes how to switch between node and NPM versions using NVM, and how to switch NPM download sources using NRM.


A, NVM

Nvm can be used to switch between node and NPM versions. When developing different projects, different versions of node and NPM may be used. Therefore, Nvm can be used to switch between different node and NPM versions.

Writing in the front

  • Before installing the Nvm, uninstall the previously installed node. Otherwise, the node version cannot be changed
  • Remove previously installed global plug-ins, otherwise the NVM command may not work. File directories are as follows
C:\Users\Administrator\AppData\Roaming\npm
C:\Users\Administrator\AppData\Roaming\npm-cache
Copy the code

The installation of NVM

Download the NVM plug-in at Github: Download NVM – Windows (NVM -setup.zip).

After the download is complete, decompress the file and double-click to install:

    1. Set up thenvmInstallation directory, the path here can be filled in according to their own needs, do not include Chinese name
    1. Set up thenodejsInstallation directory of each version. This directory isNVM install Node versionWhen storingnodejsThe directory where the
    1. When the installation is complete, type:nvm versionIf the version number is displayed, the NVM is successfully installed.

NVM common commands

  • nvm install latest: Install the latestnodejsversion
  • NVM install 11.12.0: Installs the correspondingnodejsversion
  • NVM uninstall 11.12.0: corresponds to uninstallationnodejsversion
  • nvm list available: Lists all availablenodejsversion
  • nvm list: seenvmList what has been installednodejsversion
  • NVM use 11.12.0: Use the correspondingnodejsversion
  • Enter more commands on the command linenvmTo view

Q&A

  • Note that NVM is not an internal or external command problem

    • Delete the global package installed by NPM. The file directory is as follows:
    C:\Users\Administrator\AppData\Roaming\npm
    C:\Users\Administrator\AppData\Roaming\npm-cache
    Copy the code
  • The NVM switchover node version is invalid

    • Uninstall the original node version and the global installation package
  • NVM download speed is slow

    • Find it in the NVM installation directorysettings.txtFile, add the following two lines of code:
    root: D:\DevTools\NVM\nvm
    path: D:\DevTools\NVM\nodejs
    + node_mirror: https://npm.taobao.org/mirrors/node/
    + npm_mirror: https://npm.taobao.org/mirrors/npm/
    Copy the code

Second, the NRM

In the process of using NPM, the plug-in installation may be slow, so we may use Taobao source to download and install the plug-in. Or within the company, there are some private plug-ins that can be downloaded using the company’s source. In this case, we need to set up a different source for the download. Setting it manually each time is relatively cumbersome. And NRM can solve this problem very well.

The installation of NRM

Install NRM globally
$ npm install nrm -g
Copy the code

When the installation is complete, enter the command NRM ls and you can see that there are already 6 sources by default (the one with an asterisk is the one currently in use).

* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
Copy the code

Enter NRM Use Taobao, that is, switch Registry to Taobao, and you can use the source of Taobao to install and download the plug-in.

NRM Common commands

  • nrm ls: View all configured sources and their names
  • nrm add company http://npm.xxx.cn: Add source,companyIs the name, you can name it yourself, followed by the sourceurladdress
  • nrm del company: Delete the source by namecompanyYou can delete the corresponding source
  • nrm test [registry]: Tests the speed of the source without adding the correspondingregistryName, test the speed of all sources, add the corresponding name, such ascompanyThat is testingcompanyThe velocity of the corresponding source
  • nrm use company: Switches the source and can be usedcompanyThe source of the corresponding name
  • Enter more commands on the command linenrmTo view

Three, additional knowledge points

  • Install CNPM: NPM install – g CNPM – registry=https://registry.npm.taobao.org

  • Set the installation path of the NPM global package (don’t do this if you don’t want to control the installation path yourself) :

    • Execute command:npm config set prefix "D:\DevTools\Nvm\npm-global"
    • Set environment variables: Set Path to:C:\\Users\\Administrator\\AppData\\Roaming\\npmModified toD:\\DevTools\\Nvm\\npm-global
  • To view the installed global package, run the NPM ls -g –depth=0 command

  • Set the NPM source manually

    • npm config get registry: View the current NPM source
    • npm config set registry https://registry.npm.taobao.org/: Set NPM source as Taobao
    • npm install --registry=https://registry.npm.taobao.org: Installs all dependent packages using a specific source
    • npm install express --registry=https://registry.npm.taobao.org: Installs the Express package using a specific source

4. Reference links

  • Install the NVM management NodeJS version on Windows
  • NPM Source Manager NRM tutorial