Why is my node_modules folder full of so many files I have not installed?

Viewed 1534

I'm creating a nodeJS application and struggling to upload it onto my server. I only have 6 dependencies yet for some reason my node_modules folder has 119 folder in it. Do I need the ones that I have not installed or have in my dependencies in my pack.json?

Thanks in advance!

1 Answers

Node.js is all about modularity, and with that comes the need for a quality package manager; for this purpose, npm was made. With npm comes the largest selection of community-created packages of any programming ecosystem, which makes building Node.js apps quick and easy

  • How dependencies are managed

Each library / dependency you add to your project must have a semantic version as 1.2.x and can either has other dependencies used in it or none.

So if each dependency you added to your project has its own dependencies with different versions this will make the package manager you are using add them to node_modules

Project dependencies with dependencies that are common and have no breaking API / semantic version are bubbled up to your node_modules directory and the rest of dependencies versions which aren't common live in their own node_modules directory in the libraries you added to your project

This is a general idea of how dependencies are managed and the reason for Node.js modularity.

There are also downsides to this workflow as said by Ryan Dahl the original developer of Node.js, because node_modules directory becomes bloated.

You should listen to one of his talks 10 Things I Regret About Node.js - Ryan Dahl - JSConf EU

Related