Friday, June 30, 2017

What is the difference between npm install and npm update:

I keep doing stuff that I don't understand.

I was wondering what was the reason we were instructed to always run npm install an npm update after pulling from the repository. Couldn't a single command do it?


So, here's a short note on the difference between npm install and npm update:

Sample package.json file:

{
  "name":          "my-project",
  "version":       "1.0",                             // install   update
  "dependencies":  {                                  // ------------------
    "already-installed-versionless-module":  "*",     // ignores   "1.0" -> "1.1"
    "already-installed-semver-module":       "^1.4.3" // ignores   "1.4.3" -> "1.5.2"
    "already-installed-versioned-module":    "3.4.1"  // ignores   ignores
    "not-yet-installed-versionless-module":  "*",     // installs  installs
    "not-yet-installed-semver-module":       "^4.2.1" // installs  installs
    "not-yet-installed-versioned-module":    "2.7.8"  // installs  installs
  }
}
Conclusion: The only big difference is that an already installed module with fuzzy versioning ...
  • gets ignored by npm install
  • gets updated by npm update