0

What was the reasoning behind node_modules folder? Why not just use $CWD/mymodule instead of $CWD/node_modules/mymodule. To me it seems just like unnecessary annoying sophistication, but what is the actual reason?

And a side question, can I tell npm forget about node_modules and just use '.' instead (the git way)?

exebook
  • 32,014
  • 33
  • 141
  • 226

1 Answers1

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. node_modules exists as a standardized way to always have somewhere to store a 3rd party module, without clashing any of your folders. require will also look at your node_modules 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 --prefix flag seen in this answer.

Hope this helps.

Community
  • 1
  • 1
Brennan
  • 1,764
  • 1
  • 14
  • 17