TIL: `npx npkill` to clean up your node_modules on your harddrive
Your harddisk is filled w/ node_modules
all over the place… Let’s clean it up w/ npx npkill
!
First get acustomed to the commands and options:
$ npx npkill -h
This tool allows you to list any node_modules directories in your system, as well as the space
they take up. You can then select which ones you want to erase to free up space.
┌------ CONTROLS --------------------
| SPACE: delete selected result
| Cursor UP, k: move up
| Cursor DOWN, j: move down
| h, d, Ctrl+d, PgUp: move one page down
| l, u, Ctrl+u, PgDown: move one page up
| home, end: move to the first and last result
| e: show errors popup, next page
------- PROGRESS BAR --------------------
The progress bar provides information on the search process. It has 3 parts differentiated by colors.
┌ (green) Results ready (stats calculated).
| ┌ (white) Directories examined.
| | ┌ (gray) Directories pending to be analyzed.
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-c, --bg-color Change row highlight color. Available colors are:
blue, cyan, magenta, red, white and yellow. Default
is blue.
-d, --directory Set directory from which to start searching. By
default, starting-point is .
-D, --delete-all CURRENTLY DISABLED. Automatically delete all
node_modules folders that are found.
-e, --hide-errors Hide errors if any.
-E, --exclude Exclude directories from search (directory list must
be inside double quotes "", each directory separated
by "," ) Example: "ignore1, ignore2"
-f, --full Start searching from the home of the user (example:
"/home/user" in linux).
-gb Show folder size in Gigabytes
-h, --help, ? Show this help page, with all options.
-nu, --no-check-update Dont check for updates on startup.
-s, --sort Sort results by: size, path or date (last time the
most recent file was modified in the workspace)
-t, --target Specify the name of the directory you want to search
for (by default, it's node_modules)
-x, --exclude-hidden-dirExclude hidden directories ("dot" directories) from
search.
-v, --version Show version.
Not all node_modules are bad! Some applications (like vscode, Discord, etc) need
those dependencies to work. If their directory is deleted, the application will
probably break (until the dependencies are reinstalled). NPKILL will show you
these directories by highlighting them ⚠️
We don’t catre about the hidden directories (b/c they are managed by node and such itself)
$ npx npkill -x
----- __ .__.__ .__
- ____ ______ | | _|__| | | |
------ / \\____ \| |/ / | | | |
---- | | \ |_> > <| | |_| |__ releasable space: 27.17 GB
-- |___| / __/|__|_ \__|____/____/ space saved: 11.21 GB
------- \/|__| \/ 0.11.0 search completed 518.79s
> CURSORS for select; SPACE to delete <
(needs Node 15+)
- See: NPM package
- See: Youtube Short