actualizar-desintalar-paquetes-npm

How to update or uninstall packages with NPM

  • 2 min

As we have seen, the main function of NPM is to install and manage a project’s packages and dependencies. A very important part of management is updating package versions.

NPM provides a simple way (as far as possible) to update the packages installed in our project. To update a specific package, we simply have to use the following command:

npm update nombre-paquete

This command searches for the latest version of the specified package and updates it in our project.

If no package name is specified, NPM will update all packages to their latest versions.

npm update nombre-paquete

For updating packages, NPM takes into account the versions we have specified in our package.json file. NPM will only update the package if the new version meets the established version requirements.

Uninstalling Packages

Sometimes, we may need to uninstall a package from our project. NPM provides us with a simple way (again, as far as possible) to do this using the uninstall or remove command.

To uninstall a specific package, we can use the following command:

npm uninstall nombre-paquete

This command will remove the specified package from our project. It is also possible to uninstall multiple packages at the same time, simply by specifying the package names separated by spaces.

When uninstalling a package, all dependencies that package had in our project will also be removed.

Cleaning Unused Packages

If we have installed packages that no longer appear in the package.json file, we can remove them with the command.

npm prune

The npm prune command searches for and removes any package that is not present in the dependency tree specified in package.json.

Additional Considerations

Updating packages is essential for maintaining project security and performance. You need to update packages and dependencies, that’s the way it is. Package updates can include new features or patches for security vulnerabilities. Therefore, it is important to update regularly.

Hooowever, there is also a risk that updates introduce changes that affect existing functionality. This could cause failures in your project and well… kaboom 💥.

Therefore, it is crucial to perform thorough testing before updating and have a backup plan in case of problems during the process. For example, ensuring you commit to source control always before updating or uninstalling a package.