Можете использовать один node_modules
для нескольких проектов.
Из документации
If the module identifier passed to require() is not a native module, and
does not begin with '/', '../', or './', then node starts at the
parent directory of the current module, and adds /node_modules, and
attempts to load the module from that location.
If it is not found there, then it moves to the parent directory, and
so on, until the root of the file system is reached.
For example, if the file at '/home/ry/projects/foo.js' called
require('bar.js'), then node would look in the following locations, in
this order:
/home/ry/projects/node_modules/bar.js /home/ry/node_modules/bar.js
/home/node_modules/bar.js /node_modules/bar.js
Так что просто поместите папку node_modules
в каталог ваших проектов и добавьте любые модули, которые вы хотите. Когда node
не находит каталог node_modules
в папке вашего проекта, он автоматически проверяет родительскую папку. Сделайте свою структуру каталогов такой:
-projectName
--node_modules
--myproject1
---sub-project
--myproject2
Одним из недостатков этого способа является то, что вам придется создавать файл package.json
вручную (если только кто-то не знает способ автоматизировать это с помощью grunt
или чего-то еще).