Node.js
Published in Node.js
avatar
2 minutes read

Uninstalling NPM Modules

In Node.js, you can easily uninstall NPM (Node Package Manager) modules when you no longer need them. Removing unnecessary modules helps keep your project clean and reduces the overall size of your dependencies.

Uninstalling a Single NPM Module

To uninstall a single NPM module, you can use the npm uninstall command followed by the module name. For example, to uninstall the lodash module, run the following command:

npm uninstall lodash

Replace lodash with the name of the module you want to uninstall.

Uninstalling Multiple NPM Modules

If you need to uninstall multiple NPM modules simultaneously, you can list their names after the npm uninstall command, separated by spaces. For example:

npm uninstall package1 package2 package3

Replace package1, package2, and package3 with the names of the modules you want to uninstall.

Uninstalling a Module and Removing it from Dependencies

By default, when you uninstall an NPM module, it is removed from your node_modules directory, but it remains listed in the dependencies or devDependencies section of your package.json file. To remove the module from the dependencies or devDependencies, you can add the --save or --save-dev flag when uninstalling. For example:

npm uninstall package-name --save

or

npm uninstall package-name --save-dev

The --save flag removes the module from dependencies, while the --save-dev flag removes it from devDependencies.

Verifying Uninstallation

After running the uninstallation command, you can verify if the module has been successfully uninstalled by checking your node_modules directory and package.json file.

0 Comment