NPM and Yarn are package managers that help to manage a project's dependencies. A dependency is something that a project depends on, a piece of code that is required to make the project work properly.
We need them because managing the project's dependencies is a difficult task and it quickly becomes tedious, and out of hand when the project grows. By managing dependencies, we mean to include, un-include, and update them.
Differences between npm and yarn
Installation Procedure
The lock file
- npm: npm generates a "package-lock.json" file. The package-lock.json is a little more complex due to a trade-off between determinism and simplicity. Due to this complexity, the package-lock will generate the same node_modules folder for different npm versions. Every dependency will have an exact version number associated with it in the package-lock file.
- yarn: yarn generates a "yarn.lock" file. yarn lock files help in easy merge. The merges are predictable as well, because of the design of the lock file.
Output Logs
- npm install: The npm creates massive output logs on npm commands. It is essentially a dump of stack trace of what npm is doing.
- yarn add: ******The yarn output logs are clean, visually distinguishable and brief. They are also ordered in a tree form for understandability.
Installing Global Dependencies