What is the practical difference between npm install
and npm update
? When should I use which?
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- Failed at the electron@1.8.2 postinstall script
- How to reimport module with ES6 import
- Webpack getting started, import error
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
- Get file created date in node
Many distinctions have already been mentioned. Here is one more:
Running
npm install
at the top of your source directory will run various scripts:prepublish
,preinstall
,install
,postinstall
. Depending on what these scripts do, anpm install
may do considerably more work than just installing dependencies.I've just had a use case where
prepublish
would callmake
and theMakefile
was designed to fetch dependencies if thepackage.json
got updated. Callingnpm install
from within theMakefile
would have lead to an infinite recursion, while callingnpm update
worked just fine, installing all dependencies so that the build could proceed even ifmake
was called directly.The difference between npm install and npm update handling of package versions specified in package.json:
Summary: The only big difference is that an already installed module with fuzzy versioning ...
npm install
npm update
Additionally:
install
andupdate
by default handle devDependencies differentlynpm install
will install/update devDependencies unless--production
flag is addednpm update
will ignore devDependencies unless--dev
flag is addedWhy use
npm install
at all?Because
npm install
does more when you look besides handling your dependencies inpackage.json
. As you can see in npm install you can ...PATH
) usingnpm install -g <name>
--force
npm install installs all modules that are listed on
package.json
file and their dependencies.npm update updates all packages in the
node_modules
directory and their dependencies.npm install express installs only the express module and its dependencies.
npm update express updates express module (starting with npm@2.x, it doesn't update its dependencies).
So updates are for when you already have the module and wish to get the new version.
In most cases, this will install the latest version of the module published on npm.
or better to upgrade module to latest version use:
--save
: Package will appear in your dependencies.More info: npm-install