Remove npm package from package.json
Removing an npm package from package.json is quite easy and straightforward. You can run the following command to remove or uninstall a package :
npm uninstall <package_name>
For example, let us say we want to remove the bootstrap package from the project. The command would be :
npm uninstall bootstrap
If you installed a package as a devDependency using the
--save-dev command, you need to use the
--save-dev along with the uninstall command. For example:
npm uninstall --save-dev bootstrap
How to uninstall global npm package?
Uninstalling global npm package is also very similar. To uninstall global npm package you need to run the following command:
npm uninstall -g <package_name>
For example, if you want to uninstall jsHint which say was installed globally, you can run the following command:
npm uninstall -g jshint
Once you run the uninstall command, you can notice that the folder related to the package that you uninstalled would be deleted from the node_modules folder too, and also the reference of the package in the package.json file would be removed.
I hope you have learned how to remove npm package from a project. It is important that we regularly find and remove outdated packages and unused packages from package.json. You can find the outdated and unused packages and use the command to remove these packages to keep your package dependencies in control and to avoid bloating up the build files. Hope you found the article to be helpful. Let us know in the comments.