At this point, you've probably already set up a Node environment and you've installed numerous packages for additional functionality required outside the box. Equally important, you should know how to uninstall packages you no longer need for your application to function. Keeping your application clean of unnecessary bloat is key to ensuring it runs at optimal speeds.
This tutorial will teach you how to uninstall an npm Node package locally and globally.
Uninstall Local Packages
To uninstall a package that you installed locally, navigate to the root path of your project using a command prompt tool and enter the following command:
npm uninstall [package-name]
This command will uninstall the chosen package from the project's associated
node_modules folder, but will be retained in your project's
Now, if you run the
npm install command again, it will find your removed package in the
package.json file and reinstall it as a dependency.
To remove all dependencies from your
node_modules directory and
package.json file, run the following command:
npm uninstall --save [package-name]
Remove Development Dependencies
Some packages may be development dependencies, meaning they're only needed for the development phase and not in your production environment. These would be listed as
devDependencies in your
package.json file, and must be removed by using either the
npm uninstall -D [package-name]
Uninstall Global Packages
If you need to uninstall a global package, an npm package installed for use throughout all Node projects, all you need to do is add either the
--global flag to the command:
npm uninstall -g [package-name]
With globally installed packages, you can run this command from any path in your command line tool with the same outcome.
In this article, you learned a few different ways to uninstall an NPM package via the command line. If you found this article helpful, please share it so others can use it as a resource.
You can find more information about NPM on the official NPM website.
Created: August 13, 2022