Skip to content
BENIBIX Learn

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.

Development🛠️ Editors & Tools

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.

Example
Jack runs npm install in a new React project. A folder fills up with each package the app needs.
Why it matters
Most JavaScript projects are set up and run through npm. That goes for the browser and the server.
Full entry
Development🛠️ Editors & Tools

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.

Example
Emma joins a team whose project has a yarn.lock file. She runs yarn install, not npm install, so she gets the same versions.
Why it matters
Many projects use it. You need to know which tool a project uses, or the installs will not match.
Full entry

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.