Course contentsShow
← JavaScript
Lesson 2489 of 2,72351. Package ManagementFree lesson

npm uninstall and Removing Packages

How to remove packages from your project and clean up package.json entries.

npm uninstall and Removing Packages

You'll learn how to cleanly remove npm packages from your project and keep package.json in sync.

Why Remove Packages?

Sometimes you no longer need a dependency—maybe you replaced it with a better library, decided to write the functionality yourself, or just realized it's unused. Leaving unused packages in your project bloats node_modules, slows down installs, and creates unnecessary security surface area. Think of it like cleaning out your closet: if you're not using it, get rid of it.

The Basic Command

To remove a package, use:

npm uninstall <package-name>

This does two things:

  1. Removes the package from node_modules
  2. Removes the entry from package.json dependencies

For example:

npm uninstall lodash

Variations and Aliases

NPM provides several aliases that do the same thing:

npm uninstall lodash
npm remove lodash
npm rm lodash
npm un lodash

All four commands are identical—use whichever feels most natural.

Removing Dev Dependencies

If you installed a package as a dev dependency (with --save-dev), npm uninstall still works the same way—it automatically detects whether the package is in dependencies or devDependencies and removes it from the correct location.

Global Uninstall

To remove a globally installed package:

npm uninstall -g <package-name>

This removes it from your system-wide NPM installation rather than your project.

Cleaning Up Manually

Sometimes package.json gets out of sync. You can manually delete a line from the file, then run npm install to synchronize node_modules with your manifest.

Key Takeaway: Use npm uninstall <package-name> to cleanly remove packages from both node_modules and package.json automatically, keeping your project lean and dependencies accurate.