Home >Backend Development >PHP Tutorial >javascript - Can anyone explain the difference between global installation and local installation in node.js in an easy-to-understand manner?
What are the benefits of each?
What are the benefits of each?
Simply put:
Global installation is installed to the nodejs installation directory, and the bin directory there is in your path, so you can easily call the tools there directly from the command line.
Local installation: Install it into node_modules in the local directory where package.json exists. Used to build local projects (or support nodejs running, which can be directly referenced using require).
The goals of the two are completely separate. The local one serves the project, and the global one serves as a tool.
Generally used globals include:
pm2
nrm
npm
eslint
hexo-cli
vue-cli
etc.
The most interesting thing is babel
It used to be global
Now it is recommended to be local
Try to install it locally, otherwise there may be conflicts between multiple projects on your machine.
If you still need to use it in other projects (if it’s just one project, it doesn’t matter), just use it globally, otherwise you have to install it again
In layman's terms (although it is not very appropriate), global installation means downloading and saving the data locally. When installing locally, load the downloaded content directly, otherwise it will always be obtained from the remote end.
So if it is installed locally but not globally, it will not affect the project operation. If it is installed globally but not locally, the project cannot run.