Skip to content

Updating NPM Dependencies

Keeping your project dependencies up to date is essential for security, performance, and compatibility. Below is a step-by-step guide to updating NPM dependencies.

1. Review Your package.json

Before updating, review your package.json file to control which dependencies get updated. If you do not wish to update certain packages, remove the "^" (caret) symbol from their version numbers.

2. Check for Outdated Packages

Run the following command to check which dependencies are outdated:

bash
npm outdated

This command will generate a table comparing your installed package versions with the latest available versions from the NPM registry.

Example output:

npm outdated result

3. Update Dependencies

To update all outdated packages to their latest compatible versions (according to the version constraints in package.json), use:

bash
npm update

This command ensures that your project dependencies remain up to date without introducing breaking changes.

Additional Tips:

  • To update a specific package, use:

    bash
    npm update <package-name>
  • If you want to update a package to the latest major version (which may include breaking changes), use:

    bash
    npm install <package-name>@latest
  • After updating, check your project for any issues by running:

    bash
    npm install && npm test

By following these steps, you can effectively manage and update your project dependencies while maintaining stability.

Credit @Wayne19980