How to uninstall npm modules in NodeJS
Short article on how to uninstall npm modules locally and globally from your computer completely.
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:
Related Posts
Solve npm ERR! ENOENT - No Such File or Directory Error
Learn what causes the npm ERR! ENOENT error, steps to troubleshoot it, and how to fix the no such file or directory issue when running npm start or npm install commands on your Node.js project.
How to Clear Cache in NPM?
In this tutorial we will learn how to clean or remove npm cache from Windows, linux and Mac using npm cache clean command.
How to Downgrade an Installed npm Package
Learn how to downgrade npm packages for compatibility issues, bug fixes, new features, or personal preference. Follow step-by-step guide for a easy downgrade process.
(Fixed) npm ERR! missing script: start error
This article is about how to fix npm err! missing script start error in nodejs application.
