Node command and switch node version

1. Introduction to Node.js

  1. Node.js needs to be downloaded, which is a software to run js code in the terminal window

  2. The installation package can be downloaded directly from the homepage of the official website of Node.js. It is best to use nvm to switch the node version. The usage method will be described below.

 2. The front end uses the node command to execute the JS file (master)

  1. Open a terminal in the current file
  2. node file name press Enter to execute the command
  3. Note that node can only execute JS code

3. Third-party module npm (a website that stores packages abroad)

npm (emphasis): A tool (package) for managing (downloading, uninstalling, publishing...) third-party modules.
The npm tool has already been installed on your computer when you install node.
Execute on the command line: npm -v , if you see the version number, the installation is successful.

Third-party modules -- local modules (project modules (packages))

It is best to switch the mirror source before installation. Syntax: nrm use taobao

  1. Initialize npm init and press Enter all the way.
    The code folder has no Chinese and no special symbols, then npm init -y
  2. Install. Syntax: npm install module name
             abbreviation: npm i module name module name module name
             specified version: npm i module name@version number
  3. uninstall. Syntax: npm uninstall module name
             Shorthand: npm un module name module name module name

The downloaded package can only be used in the current folder and descendant folders. If you
want to use a third-party package, you need to check the package de usage document

Third-party module -- global module (is a command (tool))

After installation, the system will have one more command
Installation does not require initialization
Global installation, any terminal path can be used

  1. Install. Syntax: npm i modulename -g / npm i -g modulename
  2. uninstall. Syntax: npm un modulename -g
  3. For globally installed modules,
    you can view the global installation path through the command npm root -g on the system disk (C drive)

Install the global package nrm

use nrm

nrm ls --- View all available mirror sources

nrm test --- View available image sources and test speed

nrm use taobao ---- switch to Taobao mirror

nrm use npm ---- switch to npm master

When installing the global package command for the first time, an error may be reported when executing the command

Let's talk about the node command to switch the node version

nvm root Check the nvm installation path address. nvm -v check nvm version

(1) Enter the command line nvm list available to view the available node.js version number

(2) Enter the command line nvm install node version number (for example: nvm install 12.17.0) to install the corresponding version and automatically install the corresponding npm version. In addition to the node.js version shown above,  other version numbers can also be downloaded, but some can be downloaded accurately, and some npm versions will not be downloaded automatically.

When the node version is too low and will not automatically download npm, you need to manually install the npm version corresponding to node. I have not tried this method. (If you use it, you can use Baidu yourself)

 After the installation is complete, you can enter the command line node -v and npm -v respectively to check whether node.js and the corresponding npm are installed successfully. If the version number can be displayed, it means that the installation is successful.

(3) After the installation is successful, enter the command line nvm use node version number (for example: nvm use 12.17.0, you must run CMD as an administrator) to select the Node.js version you are using locally. Use this command line to Switch the node.js version to run according to your own needs

 (4) Enter the command line nvm list to view all the node.js version numbers you have installed, as well as the node.js running version you currently choose (preferably according to the company's development version, otherwise the installation of the project package may not be smooth and cannot run project)

(5) If you want to delete a certain node.js version, enter the command line nvm uninstall node version number (for example: nvm uninstall 16.14.0) to delete the corresponding version

 

 The third-party module (command) @vue/cli is also bound to the node version.
Note: to run the project @vue/cli version, nodejs should be consistent with the company.

 

Because @vue/cli is a global package, it is best to uninstall the previous version when changing the version

检查 vue/cli version: vue -V

Uninstall the previous version npm uninstall -g @vue/cli

Install the version (you can also specify the version to install) npm install -g @vue/cli

 

Guess you like

Origin blog.csdn.net/m0_73089846/article/details/128468410