The relationship between node.js, npm, and nvm is well explained by the cover image. For a more in-depth understanding and introduction to commonly used commands, please see the article details.
Relationship between the Three#
-
node.js is JavaScript that runs on the server side. It is based on Google's V8 engine, which executes JavaScript very quickly and has good performance.
-
npm is the package management tool for node.js. It does not need to be installed separately and is already installed when node.js is installed. Their relationship can be compared to pip for Python.
-
nvm, short for nodejs version management, is a version management tool for node.js. It allows you to install and switch between different versions of node.js.
hexo-douban is a third-party package that can crawl Douban data. If the node.js version is too high, it will not be able to crawl the data, and you need to switch node.js to a lower version, v12.18.0.
Uninstalling and reinstalling node.js is not only very troublesome, but also may cause incompatibility issues when installing other third-party packages. Reinstalling repeatedly is not a good solution, and this is where nvm comes in.
Installation Recommendations#
Install nvm first, then install node.js
-
Download and install directly from the nvm installation address. Just click "continue" all the way. The installation package is very small and the default path is fine.
-
In the command window, use the command
nvm install <version>
to install the specified version based on the actual situation. Setversion = latest
to install the latest stable version. -
Use the command
npm install <package>
to install the extension package you need.
Common Commands#
Common nvm commands:#
nvm list available
- Displays a partial list of available versions to download.nvm list
- View the versions already installed on the computer.nvm use
- Use the specified version of node.js.- If the download of node is slow, please change the mirror source to a domestic one:
nvm node_mirror https://npm.taobao.org/mirrors/node/
- If the download of third-party packages is slow, please change the mirror source to a domestic one:
nvm node_mirror https://npm.taobao.org/mirrors/npm/
Other nvm commands:#

Common Issues:#
npm is not installed when installing nodejs with nvm#
After installing a new node using the NVM management tool, it is found that npm is not available for use.
When installing node with NVM, npm is not installed by default, so we need to download it ourselves and put it in the corresponding node directory of NVM.
Download address for npm: http://npm.taobao.org/mirrors/npm/ (Download the zip file for the corresponding version)
Corresponding npm version for each node version: https://nodejs.org/zh-cn/download/releases/
After downloading, unzip the zip file and put it in the node_modules directory of the corresponding node version in the NVM installation directory.
I extracted it to "C:\Users\cyc\AppData\Roaming\nvm\v12.22.0\node_modules".
Then rename the extracted folder to npm.
Finally, copy the npm and npm.cmd files in the bin directory of the npm folder to the root directory of the corresponding node version, as shown in the figure: