The node_modules folder is duplicated in all projects. There are a lot of folders and files and a lot of garbage. Let's say to deploy a small application on a reactor or vue js I have to wait 10-15 minutes until everything is delivered. And when I go to these folders, there are a lot of brakes.

So I go into the projects / lesson 1 folder and do npm install there. He puts everything for a long time and there appears a node_modules folder with a bunch of garbage (125 mb). projects / lesson 1 / node_modules projects / lesson 2 / node_modules projects / lesson 3 / node_modules

Is it possible to somehow indicate that this garbage does not accumulate in subfolders, but was somewhere globally?

  • Globally, versioning will be compiled for all this garbage. there is a trick here for the project to be isolated. - Artem Gorlachev
  • best of all globally if it is somewhere on the Internet. You can search on CDN. - Roman C

1 answer 1

Well, if it was added to the node_modules, then probably it is not garbage .., then the developer considered it necessary. .. if you just mean that the same modules are used in many applications and not put them individually, but they should be made common for all then npm install module_name -g but in this case you will have this package.json module, then with npm install it will install it anyway.

therefore, to make the module global and save space, you need to install it immediately (as I wrote above), then remove its name from package.json and then just do npm install

Well, in general .. it is better not to do so. Most likely, all the lessons will have almost identical modules and just change the contents of the folder, and leave node_modules as they are .. npm install does not re-download those modules that are already in node_nodules. I hope my reasoning will be clear and the answer will be useful.

  • It's clear. And there are alternatives to npm so as not to accumulate a mountain of garbage, I want to see only project files in the projects folder and that's it. Otherwise, if I have 100 projects, then a lot of extra files will be there too. Or is it forever embedded in the javascript architecture and always will be? - manking
  • Well, I wrote everything I want .. globally. but then this pile of garbage will hang around the node. that is not good for safety and just ugly. especially as the comment was higher, there may be a problem with versioning (it almost always exists in js) and the globally installed modules may be too old or too new for some other modules. in short, this is a vicious circle .. everything unfolds as it is and that’s all. In short, there is no alternative. although there is still yarn, it works a little faster, but you won’t leave the problem of the modules in node_modules. - Sergey Petrashko