NPM (Node Package Manager)

npm is the package manager for the Node JavaScript platform. Over time packages used in an application will become outdates and should be updated to newer versions.

Updating Node packages

Tested On

References

Steps

  1. Navigate to the folder with the package.json file and the node_modules directory.

    Note: If there is a new minor or patch release and we type npm update, the installed version is updated, and the package-lock.json file diligently filled with the new version.

  2. To view outdated packages:
     $ npm outdated
    

    Demo: 2020-06-21_npm_outdated.png

  3. To update to a new major version all the packages, install the npm-check-updates package globally:
     $ npm install -g npm-check-updates
    

    Demo:

    2020-06-21_install_check_updates.png

    then run the updates:

     $ ncu -u
    

    this will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version.

    Demo: 2020-06-21_ncu.png

  4. Installing the updates.

    If you just downloaded the project without the node_modules dependencies and you want to install the shiny new versions first, just run

     npm install
    

    2020-06-21_npm_install.png

    If you already had a node modules folder and just want to update it, then run:

     $ npm update
    

    Demo: 2020-06-21_update_blank.png

    Note: Running npm update in the demo is blank because nothing needed to be updated since we just ran npm install.

  5. Test if your project runs. If your project does not run, try deleting the node_modeules directory and the package.lock then recreating them with the following command (run the command in the directory where the package.json is located.)
     $ npm install
    

    Demo: 2020-06-21_install_create_lock.png

Note: If you have an error with a specific package, it may help to remove the package from node modules with npm uninstall <package name> then running npm install again.

Journal