How to delete node_modules folders.

Let us agree, we all have been there once in a while, messing up our hair while removing these long path issue with node_modules.

For a while, I used to copy paste nested npm folders outside and try deleting again and again until I delete them all. I googled around and found few other tricks that does the job fairly, but after being so used to of Node workflow, I happen to find the easiest way. So here we is what you have to do.

Enter npm prune

All you got to do is remove the node_module listings from your package json and the run `npm prune`

Lets say your package.json looks like this:

Screen Shot 2015-12-08 at 3.25.55 AM

Remove everything or may be just any particular npm which you wish to remove. Take an example, we wanted to remove all of it – then I would simply empty the dependencies like:

Screen Shot 2015-12-08 at 3.27.40 AM

Then run “npm prune” and voila. NPM will unbuild all of the node_modules folder which it didn’t find in the package.json but did locate in drive.