To reference globally installed NPM packages (i.e. packages installed with the "-g" option, like
npm install -g webpack), a NODE_PATH has to be set in your environment. I used NVM to manage node.js and here is my setting (for Mac):
Now, you can reference these packages from anywhere.
If you use other OS, check out this post on StackOverflow.
The default npm list command not only list the packages installed locally but also the packages they depend on. To most users, showing packages dependency is not necessary, as most of the time, we only want to know what is installed. To fix this, the --depth=0 option can be used:
So we get the list on the left instead of on the right:
However, this is not enough. Because if you have installed a package either
- globally or
- locally but without adding it to the package.json file
You are likely to see these errors:
To ignore these errors, a solution provided by this blog works:
To create a proper shorcut, open your .bash_profile (for Mac):
Reload the .bash_profile file and that's it!