How to uninstall npm packages in Node.js
Removing unused npm packages is essential for maintaining clean dependencies and reducing bundle size in Node.js projects.
As the creator of CoreUI, a widely used open-source UI library, I’ve managed countless package dependencies across multiple projects over 25 years of development.
From my expertise, the most reliable approach is to use the npm uninstall command, which removes the package and updates your package.json automatically.
This ensures proper dependency cleanup and prevents version conflicts.
Use npm uninstall followed by the package name to remove packages from your project.
npm uninstall lodash
npm uninstall --save-dev webpack
Here the first command removes lodash from your production dependencies, automatically updating package.json and removing it from node_modules. The second command uses --save-dev flag to remove webpack from development dependencies. The package is completely removed from your project and won’t be installed on future npm install runs.
Best Practice Note:
This is the same approach we use in CoreUI project maintenance for clean dependency management.
Always run npm audit after uninstalling packages to check for security vulnerabilities, and consider using npm ls to verify the package was properly removed from the dependency tree.



