Uninstalling npm Packages

Neelakshi Lahiri
Last Updated: May 13, 2022

Introduction

We all go through the hustle and bustle of having to put away summer clothes at the beginning of winter and winter wear when the mercury starts to rise. But why do we do that?

The answer is obvious - we don’t need those particular clothes.

Similarly, when we don’t need particular packages in a web application anymore, we’ll uninstall npm packages.

But do we know how to do that?

Then let’s not delay and find out how to uninstall npm packages.

Syntax to Uninstall npm Packages

To begin with, when we want to uninstall npm packages, we have to keep one important point in mind - are the packages installed locally or globally?

Depending on that, we uninstall npm packages.

How to Uninstall npm Packages Installed Locally

In any web application, there is a node_modules folder, where all the installed packages are. So, to uninstall npm packages, we must change our directory to that folder. 

After doing that, running the following command will uninstall the package:

npm uninstall <package-name>

 

 

Remember the package.json file that contained the name of all the packages used in a particular project?

Well, while uninstalling npm packages, we must remove them from the package.json file too. To do that, add -s or - -save to the command as shown below:

npm uninstall <package-name> -s

 

 

OR

npm uninstall <package-name> --save

 

 

How to Uninstall npm Packages Installed Globally

Now that we know how to uninstall locally installed npm packages uninstalling npm packages installed globally won’t be a problem.

The only difference in the syntax would be the addition of a -g or - -global flag.

npm uninstall -g <package-name>

 

 

OR

npm uninstall --global <package-name>

 

 

Frequently Asked Questions

  1. What are the steps to uninstall npm packages?
    The steps to uninstall npm packages are:
    1. Change the directory to the node_modules folder.
    2. Determine whether the package is installed locally or globally.
    3. Use the syntax to uninstall the package accordingly.
  2. What is the syntax to uninstall locally installed npm packages?
    The syntax to uninstall locally installed npm packages are
npm uninstall <package-name>

 

  1. What is the syntax to uninstall globally installed npm packages?
    The syntax to uninstall globally installed npm packages are:
npm uninstall -g <package-name>

 

OR

npm uninstall --global <package-name>

 

  1. How do we update the uninstalled package in the package.json file?
    To update the uninstalled package in the package.json file, we follow the given syntax:
npm uninstall <package-name> -s

 

OR

npm uninstall <package-name> --save

 

Key Takeaways

As important as it is to know how we install npm packages, we must also learn how to uninstall them. 

In this article, we learnt how to do that, but knowledge has no bounds. 

So, don’t miss the articles on CodeStudio. You can also practice coding questions on CodeStudio for interview preparation.

Happy learning!

Was this article helpful ?
0 upvotes

Comments

No comments yet

Be the first to share what you think