What is a difference between installing npm module locally and globally?
Experience Level: Senior
Tags: npm
Answer
When you install a module locally:
- It will be installed into your local folder.
- The module is then not visible outside of this folder.
- You can have multiple installations of the same module in different folders.
- You can install different versions of the same module side by side.
When you install a module globally:
- It can be used from all the other directories.
- Only one version of the module can be installed.
- You should install a module globally when you want to use it in multiple different projects without having a maintenance overhead.
Related npm job interview questions
How do you keep files out of your package when you publish a package using npm?
npm SeniorUsing npm, how do you publish a package to the public repository?
npm SeniorWhere can you find modules that the npm installed globally after you executed the npm install -g command?
npm SeniorUsing npm, how do you install a package from your local folder?
npm SeniorWhat is a npm package?
npm Junior