
Npm uninstall command
The npm uninstall
command is used to remove a package or packages from a Node.js project. It removes the specified package(s) from the node_modules
directory and updates the package.json
and package-lock.json
files accordingly. Here’s the basic usage of the npm uninstall
command:
npm uninstall <package-name>
To uninstall a specific package, replace <package-name>
with the name of the package you want to remove. For example:
npm uninstall lodash
This command will uninstall the “lodash” package from your project.
You can also uninstall multiple packages at once by providing multiple package names separated by spaces:
npm uninstall package1 package2 package3
For example:
npm uninstall lodash axios moment
This command will uninstall the “lodash”, “axios”, and “moment” packages from your project.
Additionally, you can use the --save
or --save-dev
flag to update the dependencies
or devDependencies
section of the package.json
file when uninstalling a package:
npm uninstall <package-name> --save
or
npm uninstall <package-name> --save-dev
This will remove the package from the specified section in the package.json
file, indicating that it is no longer a dependency or a devDependency.
Remember to run the npm uninstall
command from the root directory of your project where the package.json
file is located.
After running the npm uninstall
command, the package(s) will be removed from the node_modules
directory, and the relevant files will be updated accordingly.