npm package installation is divided into local installation (local) and global installation (g). From the command line you click, the difference is just whether there is -g, for example:
The code copy is as follows:
npm install grunt # local installation
npm install -g grunt-cli # Global installation
The following are explained separately.
1. When npm install xxx -g, the module will be downloaded and installed into the [Global Directory].
[Global Directory] Set by npm config set prefix "directory path".
Use npm config get prefix to get the currently set directory.
2. npm install xxx , download the module to the directory where the current command line is located.
For example:
Copy the code as follows: c:/123>npm install xxx
Will be installed to
Copy the code as follows: c:/123/node_modules/xxx
This method is obviously not good, so it is generally used to use a global installation method to install it in a directory, which is not only convenient for management, clear structure, and can be reused.