Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024

Uninstalling npm Packages

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

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>

 

 

 

Also see, Difference Between Controller and Restcontroller

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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. 

Recommended Readings:

NPX vs NPM

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

Happy learning!

Topics covered
1.
Introduction
2.
Syntax to Uninstall npm Packages
2.1.
How to Uninstall npm Packages Installed Locally
2.2.
How to Uninstall npm Packages Installed Globally
3.
Frequently Asked Questions
4.
Key Takeaways