Home >Web Front-end >Front-end Q&A >What are the differences between node's installation modes?
Difference: 1. Local installation downloads the module to the directory where the current command line is located, while global installation downloads and installs the module into the global directory, that is, under "node_modules" under the Node installation directory; 2. Local installation Installation can be introduced directly through require(), but global installation cannot use require().
The operating environment of this tutorial: windows10 system, nodejs version 12.19.0, Dell G3 computer.
1. Different installation locations:
Local installation:
npm install moduleName
then Is to download the module to the directory where the current command line is located.
Global installation:
npm install moduleName -g
The module will be downloaded and installed in the global directory, that is, under node_modules in the Node installation directory
2. The calling method is different:
In the code, local installation can be introduced directly through require(); var moduleName = require('moduleName');
Global installation is for command line (command line), such as grunt, the global installation method cannot use require to call the package;
Note:
You can set the installation mode by using npm set global=true/false , npm get global can view the currently used installation mode.
Recommended learning: "nodejs video tutorial"
The above is the detailed content of What are the differences between node's installation modes?. For more information, please follow other related articles on the PHP Chinese website!