Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abduljakul-salsalani's avatar

How to properly remove my node modules ?

I want to erase my node_modules folder because I want to save some extra space. And i don't really need node packages right now. How can i do it ?. Any ideas. I've already deleted my node_modules folder. What are the next steps should I do.

0 likes
7 replies
zachleigh's avatar

That really depends. Are you using any of the packages installed through node? Like Laravel Elixir/Mix?

1 like
jimmck's avatar

Just delete the folder. Leave your package.json alone and you can rebuild your required node modules.

1 like
zachleigh's avatar

If you dont use any node modules, then simply delete the folder.

1 like
zachleigh's avatar

Yes. So if you leave your package.json file as it is, you should (theoretically) be able to rebuild your npm dependencies. I say theoretically because it will only work if you installed your dependencies using the --save flag.

jimmck's avatar

@d3cypher Hey. Yes I treat it same as a composer.json file. As @zachleigh said. --save is for package run depends and --save-dev for development packs. They go in their depends section in package.json. I see many complaints about the storage space footprint of node files. But with the ability to delete and rebuild off the .json files can manage. Took sometime to get comfortable with composer fire dance. Now I am learning the npm/yarn fire dance. I have always been comfortable linking my own code. Like Zach refining the theory.

Please or to participate in this conversation.