How to Delete "node_modules" In a Style

Search for a command to run...

No comments yet. Be the first to comment.
As a developer working on AWS cloud, you may encounter having an S3 object that contains JSON or CSV content that you want to run a SQL query against it. You may have chosen to retrieve the entire object in your application and then filter out only t...

Recently I've been invited to the GitHub Copilot technical preview, and I can tell you it deserves all the attention it's getting! So first things first.. What is GitHub Copilot? GitHub Copilot is an AI pair programmer that helps you write code faste...

Imagine you are building a cool website. To see it, you can visit http://localhost:3000. The only problem is that the URL only works on your local computer. You could go out and buy a domain name, web server and SSL certificate then figure out how t...

Blogging on Hashnode is totally free and it is the easiest way to start a developer blog on your personal domain for free and connect with the readers through their global dev community! Everything from a custom domain mapping to faster edge caching ...

For Javascript projects, the node_modules folder is used to save all downloaded packages from npm locally in your computer. JS developers often complain that their hard drive is mysteriously always full.

Every time you start a new (side) project and enter npm install it downloads a bunch of JS files into the node_modules folder that you totally forget about after you abandon this project.

You could go to every node_modules folder and click "Right Click" then "Delete" or you can use the following command for Mac / Linux OS:
rm -rf node_modules
The command above will first delete the content of node_modules recursively until all of it is deleted, then it will remove the node_modules folder too.
If you are a senior developer, you might create a bash script to find all the node_modules folder and delete them as follow:
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
But here is how you can delete your node_modules folder in a style which I find it the smartest way to get the job done is to run:
npx npkill
It will traverse your file system and find all the node_modules folders that can be removed, give you a breakdown of their sizes and allow you to delete them one by one by hitting the space bar.

That's it!
For more details, check out npkill package.
I'd love for you to leave me a feedback below in the comments!