Npm Uninstall

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 expressCode 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 the dependencies.
  • --save-dev or -D : removes the package from devDependencies.
  • --save-optional or -O: removes the package from optionalDependencies.

To uninstall a global package, you use the --g or --global flag. The following example uninstalls the global express package:

npm uninstall express --globalCode language: Shell Session (shell)

Summary

  • Use the npm uninstall (or npm un) command to completely remove a package from a current Node project.
  • Add --global flag to the npm uninstall command to uninstall a global package.
Was this tutorial helpful ?