How to uninstall npm packages in Node.js
Uninstalling npm packages removes unnecessary dependencies from your Node.js project, reducing bundle size and maintaining clean dependency management. As the creator of CoreUI, a widely used open-source UI library, I’ve managed package dependencies across hundreds of Node.js projects, regularly cleaning up unused packages for optimal performance. From my expertise, the most effective approach is using npm uninstall with proper flags to remove packages from both node_modules and package.json. This method ensures complete package removal and maintains accurate dependency tracking for project consistency.
Use npm uninstall
with package names to remove dependencies from your Node.js project.
# Uninstall production dependency
npm uninstall lodash
# Uninstall development dependency
npm uninstall --save-dev eslint
# Uninstall multiple packages
npm uninstall express mongoose cors
# Uninstall global package
npm uninstall -g nodemon
# Remove package without updating package.json
npm uninstall --no-save react
# Verify package removal
npm list | grep package-name
The npm uninstall
command removes packages from node_modules directory and updates package.json automatically. Use --save-dev
for development dependencies and -g
for global packages. The package.json file is updated to reflect the removal, maintaining accurate dependency records.
Best Practice Note:
This is the same package management approach we use in CoreUI Node.js projects for maintaining clean dependencies. Regularly audit and remove unused packages to keep your project lightweight and reduce security vulnerabilities.