How to delete node modules

How to delete node modules

How to Delete node_modules folder from your projects

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

Table of Content

Introduction

If you are a Web Developer Or Web Designer, I can be sure that you ran at least on time (if not multiple times) npm install or yarn install to install node_modules dependencies and if you didn’t know it cost you a lot of space (about 200 MB). Imagine You have a multiple projects need to install npm modules on them?

So, You end up with a lot of wasted space and for nothing (after you compile your assets of course). Today we will learn together how to delete node_modules from all projects at once and free up space. So, let’s get started.

Requisite

All what you need to follow along with this article is a basic knowledge of terminal/command line if you are in MAC or Linux. Or command prompt if you are in Windows.

Why We Need To Free Up Hard Drive Space

I think the answer is obvious, sometimes we need more space in our machines, and we can’t find any of it, or we can delete any important file. So this is the best way to clear up space.

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

Calculate How Much Space Can Free

How much space freed after deleting node_modules? You can find out by running one command

After accessing your projects folder by running cd /path/into/projects/folder for example:

Run this command

Mac/Linux:

This command will also show how much space the folder is occupying as well

You will see something similar:

Windows:

Important Note

Before remove or delete any of your node_modules make sure you are in the right directory (e.g: where projects leaves)

Free Up Space in Linux/Mac

So, you can do it with simply running:

Free Up Space in Windows

In your command prompt/PowerShell run:

Make Your Life Easier

Conclusion

In this article we learn how to free up space in your system by deleting node_modules.

Before you leave I will let you with these notes:

That’s it for today and I hope you learned something new and useful.

Make sure to follow me on Twitter and if you have any question Just ask. I’m happy to help.

Delete Node Modules like a PRO 😎

Node modules are famous for being the heaviest object in the universe 😂 and deleting them is no joke. It takes a long of time and we even end up with freezed and unresponsive screens, but not anymore.

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

There is an npm package that could help us to delete node modules faster and without any hassle.

npkill comes to the rescue!
How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

It will then scan for node_modules starting at the path where npkill command is executed and list them.

Move between the listed node modules folders with arrow keys, and press Space to delete it.

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

Hope you liked the post and learned a trick along the way! 😃

✋ Hey! Before you go 🏃‍
If you enjoyed this trick, You can also follow me on

Most of the time once the project is completed, we will move to different projects leaving the old project folder in the system without any cleanup.

Nodejs application or npm based application node_modules will take a lot of system memory and eventually our system memory will dry up, its not easy task to find and remove all node_modules in one go.

Wrote simple CLI to do this clean that’s «mo-clean», its a simple CLI that finds the all node_modules in the system by root path and provides the details like memory taken, last used time, and path. after getting all information it will remove those node_modules from the system.

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

What it does?

It identifies the unused node_modules of NodeJS application based on last used by days and provides the details

How to use

Just install the library, don’t clone this repository and run! (you can do that but not required)

Installation

Please install the package with the flag ‘-g’.

Execution

Run the below command from the command prompt/terminal

that will prompt the user with the below options for the search or delete the node_modules

after the option selected it will prompt the path for the search or delete

Search Option

It will search for all the node_modules present under the provided path.

How to delete node modules. Смотреть фото How to delete node modules. Смотреть картинку How to delete node modules. Картинка про How to delete node modules. Фото How to delete node modules

Remove Option

It will search all the node_modules present under the provided path and delete them.

lmcneel / remove-node-modules.md

How to remove node_modules

Remove the node_modules directory

Commit All Changes

Trend20 commented Feb 11, 2021

Thanks for this solution. It worked for me

wladimirnavega commented Feb 12, 2021

Thank you very much.

christianbmartinez commented Feb 17, 2021

You helped a lot of people with this including me! Great job! I am getting very comfortable with git now, thanks to various write ups like these.

saisudhir14 commented Mar 7, 2021

easy-peasy! Thanks a lot for your gist!

shohey1226 commented Mar 15, 2021

MarcioBBS commented Mar 25, 2021

I much appreciate it!

neverkas commented Mar 31, 2021

Godwin-NJ commented Apr 18, 2021

Nice one, was helpful

PatriciaFeio commented Apr 22, 2021

vartikavr commented Apr 28, 2021

Really helpful. Thanks!

nosremetnarg commented May 7, 2021

Here to say thanks!

denokenya commented May 20, 2021

RadhikaRJ commented May 26, 2021

Thank you for this solution. It works & was helpful.

enti-re commented May 30, 2021

Finally removed
Thanks for the article

sajithatharaka commented Jun 10, 2021

Zeng95 commented Jun 12, 2021

Thank you very much! It works like a charm.

willianfrancas commented Jul 16, 2021

Thank you so much!!

holylander commented Aug 2, 2021

yeica commented Aug 14, 2021

thank you, this was so helpful ❤

jfgrissom commented Sep 19, 2021

Looks like this gift is still giving. Thanks!

gjqeriqi commented Oct 11, 2021

ismailakinkunmi commented Oct 23, 2021

SeaRauber commented Dec 15, 2021

lmcneel commented Dec 15, 2021

How to remove node_modules folder

Posted on Apr 23, 2021

Learn how to remove the entire folder or just specific packages from your node_modules folder

The node_modules folder is used to save all downloaded packages from npm in your computer for the JavaScript project that you have. Developers are always recommended to do a fresh install with npm install each time they downloaded a JavaScript project into their computer.

Still, there might be cases when you want to remove the folder from your computer. Such as when copying the project to a hard drive for backup and removing unused packages. This tutorial will show you how to remove certain npm packages and remove the whole node_modules folder from your local computer.

First, let’s see how to remove the node_modules folder entirely.

How to remove node_modules folder

To delete the node_modules folder from your JavaScript project, you can use the following command for Mac / Linux OS:

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 have multiple node_modules folders in many different projects, then you need to use the following command to find the folders and delete them all.

Go to the parent folder of all your node_modules folders and run the following command:

It will find all node_modules located inside the folder and all its subfolders. Here’s an example output from my computer:

As you can see from the output above, I have three node_modules folders inside three different subfolders. To delete them all, I need to use the following command:

For Windows, removing node_modules package may cause an error saying the source file names are larger than what is supported by the file system:

When you see this error, you need to remove the node_modules folder by using the rimraf npm package.

If you’re using npm version 5.2.0 or above, then you can use npm package runner called npx to run rimraf without installing as follows:

If your npm version is lower than 5.2.0, then you need to install the package globally using npm as follows:

Then remove the node_modules folder with the following command:

If you have many node_modules folders, then you can go to the parent folder that contains all the node_modules folder and execute rimraf with the following pattern:

The double asterisk ** pattern will make rimraf finds all node_modules folder recursively and delete them all.

Deleting specific packages from node_modules folder

At times, you may want to remove specific npm packages from your node_modules folder. You can do so by using the npm uninstall command as shown below:

Or you can also remove the package name manually from package.json file and run another npm install command. The npm install command will check your node_modules folder and remove packages that are not listed as a dependency in package.json file.

Now you know how to remove node_modules folder and removing specific packages from it 😉

Level up your programming skills

I’m sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I’ll send new stuff straight into your inbox!

About

Nathan Sebhastian is a software engineer with a passion for writing tech tutorials.
Learn JavaScript and other web development technology concepts through easy-to-understand explanations written in plain English.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *