+{"componentChunkName":"component---src-pages-markdown-remark-frontmatter-slug-tsx","path":"/code/remove-old-node-modules-directories/","result":{"data":{"markdownRemark":{"html":"<p>At the time of writing this: I have 74 Node projects in my machine. Each of them have dozens of dependencies installed in a <code class=\"language-text\">node_modules</code> directory. And a few them takes 1GB of disk space. 😱</p>\n<p>I decided to write a command that would remove <em>node modules</em> directories that I'm no longer using. For myself, I determined that any project that I haven't touched in the last 3 months was a good candidate for cleanup. Anyway, if I need to take on an old project, I would just have to <code class=\"language-text\">npm i</code> and wait a few seconds or minutes.</p>\n<p>I ended up composing 2 commands: one for checking the size of <em>node modules</em> before deleting, and the other to actually remove these directories.</p>\n<p><strong>Note:</strong> The following commands assume that all projects are under the same parent directory. From that parent directory, these commands needs to be executed.</p>\n<h2>Checking the size of old node modules</h2>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token punctuation\">\\</span>\n <span class=\"token parameter variable\">-ctime</span> +90 <span class=\"token punctuation\">\\</span>\n <span class=\"token parameter variable\">-name</span> node_modules <span class=\"token punctuation\">\\</span>\n <span class=\"token parameter variable\">-depth</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">\\</span>\n <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">du</span> <span class=\"token parameter variable\">-hs</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Removing old node modules directories</h2>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token punctuation\">\\</span>\n <span class=\"token parameter variable\">-ctime</span> +90 <span class=\"token punctuation\">\\</span>\n <span class=\"token parameter variable\">-name</span> node_modules <span class=\"token punctuation\">\\</span>\n <span class=\"token parameter variable\">-depth</span> <span class=\"token number\">2</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span></code></pre></div>\n<p>That's it! Removing old <em>node modules</em> directories have freed around 10GB from my machine. That's a win for me! Hope you find this useful.</p>","frontmatter":{"date":"2020-11-13T09:30:00.000Z","slug":"/code/remove-old-node-modules-directories","title":"Remove old node modules to claim space"}},"allMarkdownRemark":{"edges":[{"node":{"frontmatter":{"slug":"/lymphoma/2015-09-01"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-03"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-04"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-05"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-07"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-10"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-17"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-18"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-21"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-25"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-03-29"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-06"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-08"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-11"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-13"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-23"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-24"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-25"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-04-27"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-05-06"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-05-10"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-05-11"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-05-17"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-05-19"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-05-25"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-01"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-02"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-03"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-06"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-08"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-10-2"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-10"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-12"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-15"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-23"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-06-24"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-07-05"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-07-12-2"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-07-12"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-07-23"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-07-27"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-08-09"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-08-10"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-08-25"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-09-09"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-09-12"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-09-27"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-10-12"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2016-10-28"}}},{"node":{"frontmatter":{"slug":"/code/guide-create-a-node-js-command-line-package"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2018-08-22-2"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2018-08-22"}}},{"node":{"frontmatter":{"slug":"/code/remove-old-node-modules-directories"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2020-12-22"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-02-24"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-03-01"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-03-22"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-03-24"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-05-15"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-05-17"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-06-17"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-07-21"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-08-05"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-08-21"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2021-08-23"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2025-09-18"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2025-12-02"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2026-01-07"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2026-02-12"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2026-03-09"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2026-04-28"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2026-04-29"}}},{"node":{"frontmatter":{"slug":"/lymphoma/2026-05-07"}}}]}},"pageContext":{"id":"0aacddfb-2111-5a85-aed1-5e880e811f98","frontmatter__slug":"/code/remove-old-node-modules-directories","__params":{"frontmatter__slug":"code"}}},"staticQueryHashes":["2052298874"],"slicesMap":{}}
0 commit comments