node_modules
文件夹背后的原因是什么?为什么不使用$CWD/mymodule
代替$CWD/node_modules/mymodule
。对我来说,这似乎就像不必要的烦人复杂,但实际原因是什么?
还有一个问题,我可以告诉npm忘记node_modules
而只是使用'.'
(git方式)吗?
答案 0 :(得分:2)
Most larger projects that I've worked on have 10-20 dependencies. Having all of them an the root level doesn't make much sense, it becomes harder to write software that can check for outdated modules, rebuild modules, upgrade them, etc. COLUMNA COLUMNB COLUMNC COLUMND
value1 value2 value3 value9
value4 null value5 value10
null value6 value7 value11
null null value8 value12
exists as a standardized way to always have somewhere to store a 3rd party module, without clashing any of your folders. node_modules
will also look at your require
directory by default, eliminating the need for you to specify a direct path to the module.
Also, as Colonel Thirty Two mentioned, you don't want to be checking this into your git repository.
As for your side question, here is the documentation on npm folders. It doesn't look like you can install it in the root of your project, but you can specify the path to the node_modules
directory with the node_modules
flag seen in this answer.
Hope this helps.