Scenario 1:
One scenario:
You use a package that gets removed from npm. If you have all the modules in the folder node_modules, then it won't be a problem for you. If you do only have the package name in the package.json, you can't get it anymore.
If a package is less than 24 hours old, you can easily remove it from npm. If it's older than 24 hours old, then you need to contact them.
But:
If you contact support, they will check to see if removing that version of your package would break any other installs. If so, we will not remove it.
So the chances for this are low, but there is scenario 2...
Scenario 2:
An other scenario where this is the case:
You develop an enterprise version of your software or a very important software and write in your package.json:
"dependencies": {
"studpid-package": "~1.0.1"
}
You use the method function1(x)
of that package.
Now the developers of studpid-package rename the method function1(x)
to function2(x)
and they make a fault...
They change the version of their package from 1.0.1
to 1.1.0
.
That's a problem because when you call npm install
the next time, you will accept version 1.1.0
because you used the tilde ("studpid-package": "~1.0.1"
).
Calling function1(x)
can cause errors and problems now.
Pushing the whole node_modules folder (often more than 100 MB) to your repository, will cost you memory space. A few kb (package.json only) compared with hundreds of MB (package.json & node_modules)... Think about it.
You could do it / should think about it if:
the software is very important.
it costs you money when something fails.
you don't trust the npm registry. npm is centralized and could theoretically be shut down.
You don't need to publish the node_modules folder in 99.9% of the cases if:
you develop a software just for yourself.
you've programmed something and just want to publish the result on GitHub because someone else could maybe be interested in it.
If you don't want the node_modules to be in your repository, just create a .gitignore
file and add the line node_modules
.