This article was written in 2018 by Yu Shuji
Now I relive my thoughts at that time and transfer them to the Nuggets community.
When working with Node.js, you sometimes encounter the following problem:
If you copy it, it will run with an error, or even fail without an error. — — a classmate
This may be due to the Node.js version.
After our team’s experiments, we believe that first of all, a project, all users, should use the same node.js version, to execute the NPM install command; Then, we need to use node.js version management tools to manage the different versions.
On The Windows platform, we can choose the tool nVM-Windows.
Installation steps
First, delete all folders and environment variables previously associated with Node.js and NPM globally. Make sure you delete it, otherwise it won’t point to it correctly.
Next, we’ll download the installation package on Github. Releases the address.
I used to use version 1.1.5, but since NPM has migrated, we need to download the installation package of the newer version to install node.js properly.
Create a folder called nodes, preferably in the root directory of drive C, without Spaces in the folder name.
Create a folder in Nodes: NVM, node
Unzip nVM-setup. zip from the download package and install it. Specify that the NVM is installed in C:\nodes\ NVM and specify the node link as “C:// Nodes //node”. Then complete the rest of the installation.
Once the installation is complete, we can start using it.
Because we are slow to use NPM in China, the thoughtful software author provides us with two commands:
NVM node_mirror https://npm.taobao.org/mirrors/node/ for node. Js installed to provide a mirror warehouse NVM npm_mirror https://npm.taobao.org/mirrors/npm/ for NPM install a mirror warehouse
Ok, so now we’re installing our first node.js version.
NVM ls looks at the total versions of Node.js you have. The current version is preceded by an *. NVM install 6.9.5 Installs version 6.9.5. NVM use 4.7.3 uses this version.
NVM Use is used to refer to node as a shortcut to the current node.js version. The path to node is C:\nodes\node\node.exe, which is always under the shortcut.
Note:
Sometimes NVM install does not install node_modules, so node -v can run normally, but NPM -v cannot be found. In this case, you just need to delete the folder of this version and re-install NVM again.
If you are using version 6.9.5 and delete the v6.9.5 folder, you want to use NVM 4.7.3, but find that you cannot switch over. At this point, install version 6.9.5 back and switch.
With git-bash, NVM use XXX in/has no effect. You must go to a specific drive for this command to run.