when i start a project i always use npm and every start i will use
npm install
and will make node_modules
directory inside.
When finished making the project I was surprised by the size of the file is almost 200Mb. Imagine if creating more projects. My disk capacity will be burdened.
project capacity
Is there any way to prevent/reduce the size on my project folder.
For example make one file node_modules
to be used repeatedly?
Originally Answered: Why are node_modules so large? The module structure used to be completely nested, meaning multiple versions of the same modules could be nested within each other. This is no longer the case, so module sizes are not as big as they used to be.
You can use npm-prune to remove extraneous packages. Extraneous packages are packages that are not listed on the parent package's dependencies list. If the --production flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies.
Anybody can suggest if I delete node_modules folder and after re-creating it, will I get all the already installed packages back in the same way they were just before deleting? YES, you will get back all the packages listed in your package. json file.
You could remove your node_modules/ folder and then reinstall the dependencies from package. json. This would erase all installed packages in the current folder and only install the dependencies from package.
Using --save
and --save-dev
when adding dependencies will make your project more size-aware. For development size is "fine" but for production, npm will only install what ever is in dependencies
of your package.json
thus decreasing your node_modules
size (in production).
Otherwise npm prune
is a great way to clean up unused modules further decreasing the size of your project. Other than that being aware of which modules you install will be the only sure-fire way of decreasing project size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With