banner
无关风月

无关风月

当我与世界初相见
email
douban
bilibili

nodejs &npm &nvm

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.

image

Relationship between the Three#

  1. 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.

  2. 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.

  3. 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

  1. 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.

  2. In the command window, use the command nvm install <version> to install the specified version based on the actual situation. Set version = latest to install the latest stable version.

  3. Use the command npm install <package> to install the extension package you need.

Common Commands#

Common nvm commands:#

  1. nvm list available - Displays a partial list of available versions to download.
  2. nvm list - View the versions already installed on the computer.
  3. nvm use - Use the specified version of node.js.
  4. 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/
  5. 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:#

image

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.

image-20221014135606499

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.

image-20221014135733837

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:

image-20221014135751197

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.