Skip to Content

How to Uninstall npm Packages in NodeJS

At this point, you've probably already set up a Node environment and you've installed numerous packages for additional functionality required outside the box. Equally important, you should know how to uninstall packages you no longer need for your application. Keeping your application clean of unnecessary bloat is key to ensuring it runs at optimal speeds.

This tutorial will teach you how to uninstall an npm package locally and globally.

Uninstall Local npm Packages

To uninstall a local npm package, navigate to the root path of your project using a command prompt tool and enter the following command:

npm uninstall [package-name]

The above command will uninstall the chosen package from the project's associated node_modules folder, but will be retained in your project's package.json file, both located in the root directory of your application. This is to ensure locally removed packages can be installed again with the npm install command.

To prevent this and remove all dependencies from your node_modules directory and package.json file, run the following command:

npm uninstall --save [package-name]

Remove Development Dependencies

Some packages may be development dependencies, meaning they're only needed for the development phase and not in your production environment. These would be listed as devDependencies in your package.json file, and must be removed by using either the -D or --save-dev flag in the command prompt.

npm uninstall -D [package-name]

Uninstall Global npm Packages

If you need to uninstall a global npm package, all you need to do is add either the -g or --global flag to the command:

npm uninstall -g [package-name]

With globally installed npm packages, you can run this command from any path in your command line tool with the same outcome.


In this tutorial, you learned a few different ways to uninstall an npm package via the command line. If you found this to be helpful, please share it so others can use it as a resource.

Last Updated: July 20, 2023
Created: August 13, 2022


There are no comments yet. Start the conversation!

Add A Comment

Comment Etiquette: Wrap code in a <code> and </code>. Please keep comments on-topic, do not post spam, keep the conversation constructive, and be nice to each other.