How to uninstall npm modules in NodeJS

featured Image

In this short article, we will learn how to uninstall npm packages locally or globally from our node projects.

The npm packages are installed in two ways : locally and globally.

Anytime we install an npm module using npm install < package-name >, it installs the package in our node_modules folder and creates a reference in the package.json file.

Most packages are installed locally which means it is only available for the project in which they are installed.

The globally installed npm packages are available to be used by any project.

Let’s see how we can uninstall npm packages from our project.

Uninstall locally installed npm modules

To uninstall a node package that is installed locally, we have to run:

npm unistall <package-name>

from the root directory of the project. It will remove all the files related to the module from the node_modules folder and also remove its reference from the package.json file of the current project.

Optional flags provided by npm uninstall are :

-save or -S : It will remove packages from dependencies.

npm unistall < package-name > -S

-save-dev or -D : It will remove the npm package from the devDependencies

npm unistall < package-name > -D

-save-optional or -O : This flag will remove the npm package from optionalDependencies.

npm unistall <package-name> -O

It is important to note that these are optional flags. And most of the time, just using npm uninstall with the package name does our job.

Uninstall globally installed npm modules

To uninstall any globally installed npm modules we have to use the --global or -g flag with the npm uninstall command.

Let’s say we need to uninstall the nodemon package completely from our computer. To do so we will run:

npm uninstall nodemon -g

or

npm uninstall nodemon --global

This will remove nodemon package and all the files related to the package from our computer completely.

Related Articles:

How to check the list of globally installed npm packages

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *