How to uninstall npm packages?

How to uninstall npm packages?

Uninstall packages completely from a project - manually or automatically

ByMario Kandut

honey pot logo

Europe’s developer-focused job platform

Let companies apply to you

Developer-focused, salary and tech stack upfront.

Just one profile, no job applications!

This article is based on Node v16.15.1 and NPM 8.11.0.

Installing and uninstalling dependencies are core parts of working with any Node.js project. If you are just starting with Node.js, have a look at this article - how to install npm packages.

💰 The Pragmatic Programmer: journey to mastery. 💰 One of the best books in software development, sold over 200,000 times.

There are two ways to uninstall packages - manually or automatically.

Uninstalling dependencies

To uninstall a package, you have to remove it from your node_modules folder (that's where the code lives), and from package.json (listed there as a project dependency). If you only remove it in the node_modules folder and run npm install it will be reinstalled, and if you only remove the package entry in the package.json the package still exists in the node_modules folder.

But don't worry. The npm uninstall command will do both of it. Follow these steps for uninstalling dependencies:

  1. Identify the package you want to uninstall by looking in your package.json.
  2. Run the following command with the name of the package, or multiple packages separated by spaces:
npm uninstall <package1> <package2>

After successfully running the command, the NPM CLI will uninstall the package and print information to the terminal about how many packages were removed. Uninstalling removes the specified package, and all the packages it used internally as dependencies.

  1. Verify that it has been removed in the package.json, this depends on your installed npm version. Since npm version 5 (released in 2017) installing or uninstalling a dependency will update the package.json automatically. Previously it was required when installing a package to add the --save flag to add the package entry in package.json.

Uninstall global packages

If you've installed a package globally, you can uninstall it by passing the -g flag when uninstalling. For example, if you have Gatsby CLI globally installed and want to remove it:

npm uninstall -g gatsby

A helpful command is npm prune, which cleans extraneous packages in your node_modules folder. More details can be found in a future article.


  • Delete packages automatically with npm uninstall.
  • Avoid deleting packages manually.
  • Do not check your node_modules in version control.
  • Clean up node_modules with npm prune command.

Thanks for reading and if you have any questions, use the comment function or send me a message @mariokandut.

If you want to know more about Node, have a look at these Node Tutorials.

References (and Big thanks):

HeyNode, NPM Documentation - install, NPM Documentation - uninstall

More node articles:

Getting started with Webpack

How to list/debug npm packages?

How to specify a Node.js version

How to create a web server in Node.js

How to dynamically load ESM in CJS

How to convert a CJS module to an ESM

How to create a CJS module

How to stream to an HTTP response

How to handle binary data in Node.js?

How to use streams to ETL data?

How to connect streams with pipeline?

How to handle stream errors?

How to connect streams with pipe?

What Is a Node.js Stream?

Handling Errors in Node (asynchronous)

Handling Errors in Node.js (synchronous)

Introduction to errors in Node.js

Callback to promise-based functions

ETL: Load Data to Destination with Node.js

ETL: Transform Data with Node.js

ETL: Extract Data with Node.js

Event Emitters in Node.js

How to set up SSL locally with Node.js?

How to use async/await in Node.js

What is an API proxy?

How to make an API request in Node.js?

How does the Event Loop work in Node.js

How to wait for multiple Promises?

How to organize Node.js code

Understanding Promises in Node.js

How does the Node.js module system work?

Set up and test a .env file in Node

How to Use Environment Variables in Node

How to clean up node modules?

Restart a Node.js app automatically

How to update a Node dependency - NPM?

What are NPM scripts?

How to uninstall npm packages?

How to install npm packages?

How to create a package.json file?

What Is the Node.js ETL Pipeline?

What is data brokering in Node.js?

How to read and write JSON Files with Node.js?

What is package-lock.json?

How to install Node.js locally with nvm?

How to update Node.js?

How to check unused npm packages?

What is the Node.js fs module?

What is Semantic versioning?

The Basics of Package.json explained

How to patch an NPM dependency

What is NPM audit?

Beginner`s guide to NPM

Getting started with Node.js

Scroll to top ↑