npm uninstall is used to remove a package that is installed using npm install command. It also provides a couple of different flags to change the way it works. Let’s take a look at different ways to use npm uninstall :
npm uninstall package_name
It removes the package with name package_name from the current project. You need to run this in the same folder where package.json lies.
If you add -g or —global, it will remove that package in global context:
npm uninstall -g package_name
You can use -S or —save to remove the package and also it will remove it from the package.json dependencies tab.
npm uninstall -S package_name
It is similar to the above one but it will remove the package from devDependencies tab.
npm uninstall -D package_name
It will remove the package from optionalDependencies.
npm uninstall -O package_name
It doesn’t remove your package from package.json file. i.e. if you run npm install, it will install that package again.
npm uninstall --no-save package_name