Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vijayhardaha/04426b2508d9a1afce65a4af17329498 to your computer and use it in GitHub Desktop.
Save vijayhardaha/04426b2508d9a1afce65a4af17329498 to your computer and use it in GitHub Desktop.
Effortless Node.js Cleanup: Remove Package Lock Files and node_modules Folder

Node.js Cleanup: Remove Package Lock Files and node_modules Folder

If you've worked with Node.js projects, you're probably familiar with the package-lock.json, yarn.lock, pnpm-lock.yaml files, and the node_modules folder. While these are essential for managing dependencies, they can take up significant space and sometimes need a clean slate.

Here's a handy alias that removes these files and the node_modules folder from the current directory:

alias rm-node-modules='rm -v package-lock.json yarn.lock pnpm-lock.yaml && rm -rfv node_modules'

This alias allows you to declutter your project directory quickly, reclaiming valuable storage space and starting fresh when needed.

Usage

  1. Add the alias to your shell configuration file (e.g., .bashrc, .zshrc).

  2. Run source ~/.bashrc (or the corresponding file for your shell) to apply the changes.

  3. Navigate to the directory you want to clean up.

  4. Use rm-node-modules in your terminal, and it will remove the specified files and the node_modules folder, providing verbose output so you can see the cleanup progress.

Note: Please exercise caution when using this alias, as it will irreversibly delete these files and folders.

Conclusion

In Node.js development, managing dependencies is crucial, but cleaning up your project directory can be equally important. With the rm-node-modules alias, you can easily remove package-lock.json, yarn.lock, pnpm-lock.yaml, and the node_modules folder, simplifying your workspace and ensuring a fresh start when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment