![]() |
NPM, which stands for Node Package Manager, is the default package manager of Node.js. Developed by Isaac Z. Schlueter, NPM is written in JavaScript and was initially released on the 12th of January, 2010. Removing npm packages is a common task in Node.js development, whether you’re cleaning up dependencies, troubleshooting issues, or streamlining your project’s footprint. In this guide, we’ll walk through the various methods to uninstall npm packages from your project. Table of Content Removing Package using npmTo remove a package using the npm package manager, we can employ the command npm uninstall. The command npm uninstall is used to uninstall a package whether it is local or global. npm uninstall package_name [package_names]
Here, package_name: The name of packages to uninstall. Removing Packages from package.jsonWhen you uninstall a package using npm uninstall, npm automatically removes the package from your package.json file’s dependencies or devDependencies section. If you want to remove a package from your project’s dependencies without uninstalling it, you can use the –save or –save-dev flag: npm uninstall --save <package-name> # Removes from dependencies Removing Multiple PackagesYou can uninstall multiple packages simultaneously by providing their names separated by spaces: npm uninstall package1 package2 package3
Removing Globally Installed PackagesThe npm uninstall command can also be used to remove a package from the global environment. The -g option allows this to take place. In the following command we remove the mongoose package from the global environment: npm uninstall -g <package-name>
Example: npm uninstall -g mongoose
Output: ![]() Uninstall mongoose package Uninstall Specific Version PackageThe npm uninstall command can be used to remove only a specific version of a package. The following command uninstalls the version 4.18 of express package. The number after the @ symbol specifies the version. npm uninstall [email protected]
Output: ![]() Uninstall express version 4.18 Uninstalling all Unused PackagesThe npm package manager provides the command npm prune which can be used to all the unused packages. We can use the npm prune command as follows: npm prune
Output: ![]() Remove all the unused libraries ConclusionUninstalling npm packages is a straightforward process using the npm CLI. Whether you’re removing individual packages, cleaning up unused dependencies, or managing global installations, npm provides flexible options to streamline your Node.js projects. By regularly reviewing and removing unnecessary packages, you can keep your projects lean and maintainable. |
Reffered: https://www.geeksforgeeks.org
Node.js |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |