|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "wipe modules" |
| 4 | +description: "A little agent that removes the node_modules folder of non-active projects" |
| 5 | +category: bash |
| 6 | +tags: [nodejs, utility, utils] |
| 7 | +--- |
| 8 | + |
| 9 | +# wipe-modules |
| 10 | + |
| 11 | +> A little agent that removes the node_modules folder of non-active projects |
| 12 | +
|
| 13 | + |
| 14 | +## Why |
| 15 | + |
| 16 | +If you're a Javascript developer, you know the `node_modules` directory holds thousands or even millions of files, resulting in taking a lot of space in your hard disk. |
| 17 | + |
| 18 | +Enter `wipe-modules`, a little agent that wipes (eats, literally) that big `node_modules` directory of non-active projects. |
| 19 | + |
| 20 | +Why in Earth would you want to have those monster-sized `node_modules` folders on inactive projects? You got your `package.json` to recreate it whenever you want, right? |
| 21 | + |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +``` |
| 26 | +$ wipe-modules --help |
| 27 | +
|
| 28 | + Usage: wipe-modules [path] [days] |
| 29 | +
|
| 30 | + Path: |
| 31 | + The full path of your code directory |
| 32 | +
|
| 33 | + Days: |
| 34 | + The days you want to set to mark projects as inactive |
| 35 | +
|
| 36 | + Example: wipe-modules ~/code 30 |
| 37 | +
|
| 38 | + That will remove the node_modules of your ~/code projects |
| 39 | + whose been inactive for 30 days or more. |
| 40 | +``` |
| 41 | + |
| 42 | + |
| 43 | +## Using cron |
| 44 | + |
| 45 | +`wipe-modules` can be executed as a background job using using [cron](https://en.wikipedia.org/wiki/Cron) |
| 46 | + |
| 47 | +The default included `cron-file` file holds the following syntax: |
| 48 | + |
| 49 | +`0 11 * * * $HOME/bin/wipe-modules ~/code_dir 30` |
| 50 | + |
| 51 | +That is the crontab (cron table) file, it instructs cron to run the `wipe-modules ~/code_dir 30` script everyday at 11:00 am. |
| 52 | + |
| 53 | +Edit the `cron-file` to match your own needs, see [how to set up a crontab](https://en.wikipedia.org/wiki/Cron#Overview) for more info. |
| 54 | + |
| 55 | +Now set the `cron-file` crontab file in cron using: |
| 56 | + |
| 57 | +`` |
| 58 | +$ crontab ~/path_to_cronfile/cron-file |
| 59 | +`` |
| 60 | + |
| 61 | +And you're done! |
| 62 | + |
| 63 | +To check if you've successfully added your crontab type: |
| 64 | + |
| 65 | +`` |
| 66 | +$ crontab -l |
| 67 | +`` |
| 68 | + |
| 69 | +It should display your crontab. |
| 70 | + |
| 71 | +To edit a crontab, use `crontab -e` and to delete all crontabs use `crontab -r`. |
| 72 | + |
| 73 | +Note that `crontab -r` will destroy all your crontabs, that's why it's a good idea to keep your crontab commands in a `cron-file`. |
| 74 | + |
| 75 | +Cron is only supported in unix operating systems. |
| 76 | + |
| 77 | + |
| 78 | +## Links |
| 79 | + |
| 80 | +* [Source Code (Github)](https://github.com/bntzio/wipe-modules) |
| 81 | +* [Author: Enrique Benitez](https://bntz.io) |
| 82 | +* [Contact (Twitter)](https://twitter.com/bntzio) |
| 83 | + |
| 84 | + |
| 85 | +## License |
| 86 | + |
| 87 | +MIT © [Enrique Benitez](https://bntz.io) |
0 commit comments