Borek Borek - 3 months ago 119x
Node.js Question

npm install vs. update - what's the difference?

Newbie question but I haven't seen answered clearly - what is the practical difference between

npm install
npm update
? When to use which?


The difference between npm install and npm update:


  "name":          "my-project",
  "version":       "1.0",                             // install   update
  "dependencies":  {                                  // ------------------
    "already-installed-versionless-module":  "*",     // ignores   "1.0" -> "1.1"
    "already-installed-versioned-module":    "3.4.1"  // ignores   ignores
    "not-yet-installed-versionless-module":  "*",     // installs  installs
    "not-yet-installed-versioned-module":    "2.7.8"  // installs  installs

Conclusion: The only big difference is that an already installed versionless module ...

  • gets ignored by npm install
  • gets updated by npm update

Why use npm install at all?

Because npm install does more when you look besides handling your dependencies in package.json. As you can see in npm install you can ...

  • manually install node-modules
  • set them as global (which puts them in the shell's PATH) using npm install -g <name>
  • install certain versions described by git tags
  • install from a git url
  • force a reinstall with --force