header banner
Default

How to Use npkill to Delete the Node Modules Folder


Don't let unused packages bog down your drives, get rid of them with npkill.

Trash bin with recycle symbol

Node.js is a JavaScript runtime environment that allows you to run JavaScript outside web browsers, making it a popular choice for developing all kinds of applications. Part of its popularity is due to the plethora of NPM packages out there to ease the developer experience.

However, these packages can consume quite a lot of space on your disk, and you might not want to keep them around after completing the development process. Learn how to clean these unwanted packages from the node_modules folder with npkill.

What Is npkill and How Can You Use It?

npkill is a lightweight NPM package that allows you to easily find and remove old and heavy node_modules folders. Before you get started using npkill, make you have Node.js and NPM installed on your computer.

Running npkill is a pretty straightforward process and does not require you to install any additional dependencies. You can access it by running this command in the terminal:

 npx npkill 

This command will scan for all the node_modules folders starting at the path where the command was executed and display them along with the amount of space they take up on your disk.

Running npkill on terminal

Using this interactive tool, you can pick the projects that you no longer actively develop and delete the dependency files and folders seamlessly, with just the press of a button.

You can use the arrow keys to move between the listed folders and the Space Bar to delete the selected folder. Once done, use the Q key or Ctrl + C keys to exit the interactive menu.

Stay Cautious While Deleting the Folders

npkill is a handy tool for deleting unwanted files of old projects that you no longer maintain. However, deleting the node_modules folder of active projects will require you to reinstall them before you can run the app again. It's recommended that you proceed with caution while deleting any folder as this action is irreversible.

New to the Node.js ecosystem or transitioning from a different technology? Here's everything you need to know to get started with Node.js development.

Sources


Article information

Author: Samuel Lewis

Last Updated: 1704132242

Views: 680

Rating: 4.2 / 5 (36 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Samuel Lewis

Birthday: 1985-07-17

Address: 0396 Andrew Dam Apt. 134, South Justin, WV 35432

Phone: +4240476060066408

Job: IT Consultant

Hobby: Beekeeping, Billiards, DIY Electronics, Playing Piano, Cycling, Magic Tricks, Gardening

Introduction: My name is Samuel Lewis, I am a valuable, brilliant, venturesome, cherished, resolved, strong-willed, accessible person who loves writing and wants to share my knowledge and understanding with you.