npm update
and npm install
are two commands used in the Node.js ecosystem for managing packages.
npm install
is used to install a package or a set of packages from the npm registry. This command reads the package.json file and installs all the dependencies listed in it. For example, if you run npm install express
, it will install the latest version of the Express package and add it to the dependencies in your package.json file.
On the other hand, npm update
is used to update the installed packages to their latest version. This command will update all the packages that are currently installed to their latest version according to the version range specified in the package.json file. If the version range is not specified, it will update the packages to the latest stable version available.
So, the main difference between npm install
and npm update
is that the former installs the packages while the latter updates the installed packages to their latest versions.
Summary: The only big difference is that an already installed module with fuzzy versioning …
- gets ignored by
npm install
- gets updated by
npm update
Additionally: install
and update
by default handle devDependencies differently
npm install
will install/update devDependencies unless--production
flag is addednpm update
will ignore devDependencies unless--dev
flag is added
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
) usingnpm install -g <name>
- install certain versions described by git tags
- install from a git url
- force a reinstall with
--force