Summary: in this tutorial, you will learn how to use the npm uninstall
command to uninstall a package.
Introduction to npm uninstall command
To remove a package from your current Node project, you use the npm uninstall
command:
npm uninstall <package_name>
Code language: Shell Session (shell)
the npm uninstall
command has the following aliases: npm un
, npm remove
, npm rm
, and npm unlink
.
The npm uninstall
command completely removes the package and its dependencies from the current project. It also updates the package.json
file.
For example, the following command removes the express
module from the npm-demo
project:
npm uninstall express
Code language: Shell Session (shell)
If you view the package.json file, you’ll see that the express package has been removed.
By default, the npm uninstall command takes 3 exclusive, optional flags:
--save
or-S
: removes the package from thedependencies
.--save-dev
or-D
: removes the package fromdevDependencies
.--save-optional
or-O
: removes the package fromoptionalDependencies
.
To uninstall a global package, you use the --g
or --global
flag. The following example uninstalls the global express
package:
npm uninstall express --global
Code language: Shell Session (shell)
Summary
- Use the
npm uninstall
(ornpm un
) command to completely remove a package from a current Node project. - Add
--global
flag to thenpm uninstall
command to uninstall a global package.