npkill
List any node_modules ๐ฆ dir in your system and how heavy they are. You can then select which ones you want to erase to free up space ๐งน
Top Related Projects
Move files and folders to the trash
node.js command-line interfaces made easy
๐ Terminal string styling done right
yargs the modern, pirate-themed successor to optimist.
A `rm -rf` util for nodejs
Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
Quick Overview
npkill is a command-line tool designed to help developers find and remove node_modules directories to free up disk space. It provides an interactive interface to easily identify and delete unnecessary node_modules folders across multiple projects, helping to manage storage efficiently.
Pros
- Interactive and user-friendly interface
- Quickly scans and identifies node_modules directories
- Provides size information for each node_modules folder
- Allows selective deletion of node_modules directories
Cons
- Limited to node_modules directories only
- May accidentally delete necessary node_modules folders if not used carefully
- Requires manual navigation through the file system
- Performance may decrease when scanning large file systems
Getting Started
To install and use npkill, follow these steps:
-
Install npkill globally using npm:
npm install -g npkill
-
Run npkill in your desired directory:
npkill
-
Use arrow keys to navigate, space to select/deselect, and enter to delete selected folders.
-
To specify a custom directory, use the
-d
or--directory
flag:npkill -d /path/to/your/projects
-
For additional options and flags, refer to the help command:
npkill --help
Competitor Comparisons
Move files and folders to the trash
Pros of trash-cli
- Cross-platform support (macOS, Linux, Windows)
- Moves files to the system trash instead of permanent deletion
- Simple and focused functionality
Cons of trash-cli
- Limited to trashing files and directories
- Lacks advanced features for managing node_modules
Code comparison
trash-cli:
import trash from 'trash';
await trash(['*.png', '!important.png']);
npkill:
import { npkill } from 'npkill';
npkill({
path: './',
interactive: false,
deleteAll: true
});
Key differences
npkill is specifically designed for managing and removing node_modules directories, while trash-cli is a general-purpose tool for moving files and directories to the system trash. npkill offers an interactive mode and focuses on freeing up disk space from unused node_modules, whereas trash-cli provides a safer alternative to permanent deletion for any file or directory.
Use cases
- Use npkill when you need to clean up node_modules directories and free up disk space in JavaScript/Node.js projects
- Use trash-cli when you want a cross-platform way to safely delete files by moving them to the system trash
Both tools serve different purposes and can be valuable in a developer's toolkit, depending on the specific task at hand.
node.js command-line interfaces made easy
Pros of commander.js
- More versatile and feature-rich for building complex CLI applications
- Extensive documentation and large community support
- Supports command-specific options and nested subcommands
Cons of commander.js
- Steeper learning curve for beginners
- Requires more setup and configuration for simple CLI tools
- Larger package size and potential overhead for small projects
Code Comparison
npkill:
program
.option('-r, --root <dir>', 'Set the root directory to start searching')
.option('-f, --full', 'Show the full path of directories')
.parse(process.argv);
commander.js:
program
.option('-d, --debug', 'output extra debugging')
.option('-s, --small', 'small pizza size')
.option('-p, --pizza-type <type>', 'flavour of pizza')
.parse(process.argv);
Summary
npkill is a specialized tool for removing node_modules directories, while commander.js is a comprehensive solution for building CLI applications. npkill offers a simpler, more focused approach, while commander.js provides greater flexibility and features for complex CLI tools. The choice between them depends on the specific requirements of your project and the level of CLI functionality needed.
๐ Terminal string styling done right
Pros of Chalk
- Focused on terminal string styling, providing a wide range of color and formatting options
- Highly popular and well-maintained, with extensive community support
- Lightweight and easy to integrate into various Node.js projects
Cons of Chalk
- Limited in scope, only handles text styling
- Requires additional dependencies for more complex terminal operations
- Not designed for specific tasks like managing node_modules directories
Code Comparison
Chalk usage:
import chalk from 'chalk';
console.log(chalk.blue('Hello world!'));
npkill usage:
import { npkill } from 'npkill';
npkill({
path: './',
deleteAll: true
});
Summary
Chalk is a specialized library for terminal string styling, offering a wide range of color and formatting options. It's lightweight and widely adopted in the Node.js ecosystem. However, its functionality is limited to text styling and doesn't address specific tasks like managing node_modules directories.
npkill, on the other hand, is a tool designed for a specific purpose: cleaning up node_modules folders. It offers functionality to search for and remove unnecessary node_modules directories, which can help free up disk space and improve project organization.
While both tools are useful in their respective domains, they serve different purposes and are not directly comparable in terms of functionality. The choice between them depends on the specific needs of your project.
yargs the modern, pirate-themed successor to optimist.
Pros of yargs
- More versatile and feature-rich command-line argument parser
- Extensive documentation and large community support
- Highly customizable with advanced features like command grouping and middleware
Cons of yargs
- Steeper learning curve due to its extensive API
- Potentially overkill for simple CLI applications
- Larger package size compared to npkill
Code Comparison
npkill:
const cli = meow(`
Usage
$ npkill
Options
--directory, -d Set directory to analyze
--force, -f Delete files without prompt
`, {
flags: {
directory: {
type: 'string',
alias: 'd'
},
force: {
type: 'boolean',
alias: 'f'
}
}
});
yargs:
const argv = require('yargs')
.option('directory', {
alias: 'd',
describe: 'Set directory to analyze',
type: 'string'
})
.option('force', {
alias: 'f',
describe: 'Delete files without prompt',
type: 'boolean'
})
.help()
.argv;
While npkill uses meow for simple CLI argument parsing, yargs offers a more structured and feature-rich approach to defining and handling command-line options.
A `rm -rf` util for nodejs
Pros of rimraf
- Widely adopted and battle-tested in the Node.js ecosystem
- Supports both synchronous and asynchronous operations
- Lightweight with minimal dependencies
Cons of rimraf
- Limited to removing files and directories
- Lacks a user interface for interactive file management
- Does not provide detailed information about removed files
Code Comparison
rimraf:
const rimraf = require('rimraf');
rimraf('/path/to/directory', (error) => {
if (error) console.error('Error:', error);
else console.log('Directory removed');
});
npkill:
const npkill = require('npkill');
npkill.start({
path: '/path/to/directory',
deleteAll: true,
exclude: ['important-folder']
});
Key Differences
- rimraf focuses solely on file and directory removal, while npkill specializes in managing node_modules folders
- npkill provides an interactive CLI interface, whereas rimraf is primarily used programmatically
- npkill offers more advanced features like folder size calculation and exclusion patterns
- rimraf is more lightweight and suitable for general file system operations, while npkill is tailored for Node.js project cleanup
Both tools serve different purposes within the Node.js ecosystem, with rimraf being a general-purpose removal utility and npkill focusing on optimizing disk space by managing node_modules folders.
Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
Pros of node-fs-extra
- Provides a comprehensive set of file system operations, extending Node's built-in
fs
module - Well-established and widely used in the Node.js ecosystem
- Offers both synchronous and asynchronous versions of methods
Cons of node-fs-extra
- Not specifically designed for cleaning up node_modules folders
- Requires more manual coding to achieve the same result as npkill
- May have a steeper learning curve for beginners
Code Comparison
npkill:
import { npkill } from 'npkill';
npkill({
path: './',
deleteAll: true
});
node-fs-extra:
const fs = require('fs-extra');
fs.remove('./node_modules', err => {
if (err) return console.error(err);
console.log('node_modules deleted');
});
While npkill is specifically designed for cleaning up node_modules folders, node-fs-extra is a more general-purpose file system utility. npkill offers a simpler API for its specific use case, while node-fs-extra provides more flexibility but requires more manual implementation for the same task. node-fs-extra is better suited for projects that need a wide range of file system operations, while npkill is ideal for quickly cleaning up node_modules folders across multiple projects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Easily find and remove old and heavy node_modules folders :sparkles:
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. Yay!
i18n
We're making an effort to internationalize the Npkill docs. Here's a list of the available translations:
Table of Contents
:heavy_check_mark: Features
-
Clear space: Get rid of old and dusty node_modules cluttering up your machine.
-
Last Workspace Usage: Check when was the last time you modified a file in the workspace (indicated in the last_mod column).
-
Very fast: NPKILL is written in TypeScript, but searches are performed at a low level, improving performance greatly.
-
Easy to use: Say goodbye to lengthy commands. Using npkill is as simple as reading a list of your node_modules, and pressing Del to get rid of them. Could it be any easier? ;)
-
Minified: It barely has any dependencies.
:cloud: Installation
You don't really need to install it to use it! Simply use the following command:
$ npx npkill
Or if for some reason you really want to install it:
$ npm i -g npkill
# Unix users may need to run the command with sudo. Go carefully
NPKILL does not support node<v14. If this affects you you can use
npkill@0.8.3
:clipboard: Usage
$ npx npkill
# or just npkill if installed globally
By default, npkill will scan for node_modules starting at the path where npkill
command is executed.
Move between the listed folders with รขยย รขยย, and use Space or Del to delete the selected folder. You can also use j and k to move between the results.
You can open the directory where the selected result is placed by pressing o.
To exit, Q or Ctrl + c if you're brave.
Important! Some applications installed on the system need their node_modules directory to work and deleting them may break them. NPKILL will highlight them by displaying a :warning: to be careful.
Options
ARGUMENT | DESCRIPTION |
---|---|
-c, --bg-color | Change row highlight color. (Available: blue, cyan, magenta, white, red and yellow) |
-d, --directory | Set the directory from which to begin searching. By default, starting-point is . |
-D, --delete-all | Automatically delete all node_modules folders that are found. Suggested to be used together with -x . |
-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 folders in Gigabytes instead of Megabytes. |
-h, --help, ? | Show this help page and exit |
-nu, --no-check-update | Don't check for updates on startup |
-s, --sort | Sort results by: size , path or last-mod |
-t, --target | Specify the name of the directories you want to search (by default, is node_modules) |
-x, --exclude-hidden-directories | Exclude hidden directories ("dot" directories) from search. |
--dry-run | It does not delete anything (will simulate it with a random delay). |
-v, --version | Show npkill version |
Warning: In future versions some commands may change
Examples
- Search node_modules directories in your projects directory:
npkill -d ~/projects
# other alternative:
cd ~/projects
npkill
- List directories named "dist" and show errors if any occur:
npkill --target dist -e
- Displays the magenta color cursor... because I like magenta!
npkill --color magenta
- List vendor directories in your projects directory, sort by size, and show size in gb:
npkill -d '~/more projects' -gb --sort size --target vendor
- List node_modules in your projects directory, excluding the ones in progress and ignore-this directories:
npkill -d 'projects' --exclude "progress, ignore-this"
- Automatically delete all node_modules that have sneaked into your backups:
npkill -d ~/backups/ --delete-all
:pager: Set Up Locally
# -- First, clone the repository
git clone https://github.com/voidcosmos/npkill.git
# -- Navigate to the dir
cd npkill
# -- Install dependencies
npm install
# -- And run!
npm run start
# -- If you want to run it with some parameter, you will have to add "--" as in the following example:
npm run start -- -f -e
:crystal_ball: Roadmap
- Release 0.1.0 !
- Improve code
- Improve performance
- Improve performance even more!
- Sort results by size and path
- Allow the search for other types of directories (targets)
- Reduce dependencies to be a more minimalist module
- Allow to filter by directories that have not been used in a period of time
- Create option for displaying directories in tree format
- Add some menus
- Add log service
- Periodic and automatic cleaning (?)
:bug: Known bugs :bug:
- Sometimes, CLI is blocked while folder is deleting.
- Some terminals that do not use TTY (like git bash in windows) do not work.
- Sorting, especially by routes, can slow down the terminal when there are many results at the same time.
- Sometimes, size calculations are higher than they should be.
- (SOLVED) Performance issues when searching from high level directories (like / in linux).
- (SOLVED) Sometimes text collapses when updating the cli.
- (SOLVED) Analyzing the size of the directories takes longer than it should.
If you find any bugs, don't hesitate and open an issue :)
:revolving_hearts: Contributing
If you want to contribute check the CONTRIBUTING.md
:coffee: Buy us a coffee
We have developed npkill in our free time, because we are passionate about the programming sector. Tomorrow we would like to dedicate ourselves to this, but first, we have a long way to go.We will continue to do things anyway, but donations are one of the many ways to support what we do.
Thanks!!
A huge thank you to our backers :heart:
Crypto alternative
- btc: 1ML2DihUoFTqhoQnrWy4WLxKbVYkUXpMAX
- bch: 1HVpaicQL5jWKkbChgPf6cvkH8nyktVnVk
- eth: 0x7668e86c8bdb52034606db5aa0d2d4d73a0d4259
:scroll: License
MIT รยฉ Nya Garcรยญa Gallardo and Juan Torres Gรยณmez
:cat::baby_chick:
Top Related Projects
Move files and folders to the trash
node.js command-line interfaces made easy
๐ Terminal string styling done right
yargs the modern, pirate-themed successor to optimist.
A `rm -rf` util for nodejs
Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot