33

Would someone please explain the difference between ng update in Angular 6 and npm update?

andrewJames
  • 19,570
  • 8
  • 19
  • 51
saravana va
  • 1,081
  • 1
  • 13
  • 17
  • `ng` refers to `@angular/cli` while `npm` is the Node Package Manager. – SiddAjmera Sep 01 '18 at 13:49
  • 6
    this may be [useful](https://blog.angular.io/version-6-of-angular-now-available-cc56b0efa7a4), it appears that ng update uses npm under the hood and also applies its own knowledge to automatically adujst your (angular) project files with new dependencies – Dale Sep 01 '18 at 13:51
  • 4
    This is a legitimate question and shouldn't be downvoted. It's important to know the difference between the two. – Crono Feb 06 '19 at 13:43
  • Yeah I'd agree ng = CLI and npm = all your packages. You'll forget this in 30 days, find this posting again and jog your memory :). Happens to me 3 times a year. Even if ng somehow intelligently updates npm packages under the hood that makes me wonder if a npm update does it different and is that bad? – Mark Aug 01 '20 at 15:50

2 Answers2

15

ng update: Updates the current application to latest versions.

Just like Web and the entire web ecosystem, Angular is continuously improving. Angular balances continuous improvement with a strong focus on stability and making updates easy. Keeping your Angular app up-to-date enables you to take advantage of leading-edge new features, as well as optimizations and bug fixes.

This document contains information and resources to help you keep your Angular apps and libraries up-to-date.

npm update: This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.

It will also install missing packages. As with all commands that install packages, the --dev flag will cause devDependencies to be processed as well.

If the -g flag is specified, this command will update globally installed packages.

If no package name is specified, all packages in the specified location (global or local) will be updated.

As of npm@2.6.1, the npm update will only inspect top-level packages. Prior versions of npm would also recursively inspect all dependencies. To get the old behavior, use npm --depth 9999 update.

As of npm@5.0.0, the npm update will change package.json to save the new version as the minimum required dependency. To get the old behavior, use npm update --no-save.

sources:
https://github.com/angular/angular-cli/wiki/update
https://docs.npmjs.com/cli/update

Ayoub k
  • 7,788
  • 9
  • 34
  • 57
2

ng update does more than npm update

ng update will update your dependencies (same as npm update), but in addition to that, it can also run update-schematics: library authors may include such schematics to automatically update your code (i.e. your typescript) files during the update process: i.e. they can fix breaking changes directly in your code.

From ng-update: Library Developers:

Libraries are responsible for defining their own update schematics. The ng update tool will update the package.json, and if it detects the "ng-update" key in package.json of the library, will run the update schematic on it (with version information metadata).

If a library does not define the "ng-update" key in their package.json, they are considered not supporting the update workflow and ng update is basically equivalent to npm install.

When ng update has finished:

  • your package.json file will include the updated versions
  • the packages are installed in the node_modules folder
  • your source-code may have been changed by the update-schematics So now is a good time to use your version control system to inspect the changes and test your application.
TmTron
  • 17,012
  • 10
  • 94
  • 142