npm vs Yarn
People think Yarn has its own store of packages, apart from npm, and it does not. Yarn and npm both fetch from the same npm registry. They differ in how they install, and in the lockfile they write. npm writes package-lock.json, and Yarn writes yarn.lock. A project should pick one and stick to it.
npm
The tool for getting JavaScript packages. It is also the big shelf they come from.
npm is the package tool for JavaScript, and it comes with Node.js. It is also the name of the online registry where JavaScript packages are shared. It holds millions of packages, more than any other registry. The npm install command fetches packages. A file named package.json lists what a project needs. npm can also run a project's scripts, like npm test.
Yarn
A tool that adds code packages to JavaScript apps. It is used in place of npm.
Yarn is a free package manager for JavaScript, used in place of npm. It fetches packages from the same npm registry. You add a package with yarn add, and it writes a lockfile called yarn.lock. Yarn came early with ideas like lockfiles and fast offline installs. Teams pick it for speed and for its tools for big projects made of many parts.
In one line
- npm
- The tool for getting JavaScript packages. It is also the big shelf they come from.
- Yarn
- A tool that adds code packages to JavaScript apps. It is used in place of npm.