You can achieve something close to what you are describing with the link
option.
From https://docs.npmjs.com/misc/config#link:
If true, then local installs will link if there is a suitable globally installed package.
Note that this means that local installs can cause things to be installed into the global space at the same time. The link is only done if one of the two conditions are met:
- The package is not already installed globally, or
- the globally installed version is identical to the version that is being installed locally.
So you will still have some files in each project's node_modules
, but you shouldn't have as large a folder.
To turn this behavior on, run:
npm config set link -g
Edit: There is no way you can avoid running npm install
and having a node_modules
folder. Node.js always looks in node_modules
for dependencies (this behavior pre-dates npm
itself). The link
option will make npm
create symlinks in node_modules
, pointing to a common pool. That will reduce disc usage, but you cannot do away with node_modules
.