Open In App

Difference between npm and yarn


NPM and Yarn are package managers that help to manage a project’s dependencies. A dependency is, as it sounds, 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 the dependencies, we mean to include, un-include, and update them.

npm: It is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command-line client, also called npm, and an online database of public and paid-for private packages called the npm registry.



yarn: It stands for Yet Another Resource Negotiator and it is a package manager just like npm. It was developed by Facebook and is now open-source. The intention behind developing yarn(at that time) was to fix performance and security concerns with npm.

The differences between npm and yarn are explained below:



Installation procedure

The lock file

Output log

Installing global dependencies

The ‘why’ command:

License Checker

Fetching packages

Commands changed in yarn after npm

command npm yarn
Install dependencies npm install yarn
Install package npm install package_name
npm install package_name@version_number
yarn add package_name
yarn add package_name@version_number
Uninstall package npm uninstall package_name yarn remove package_name
Install dev package npm install package_name –save-dev yarn add package_name –dev
Update dev package npm update package_name
npm update package_name@version_number
yarn upgrade package_name
yarn upgrade package_name@version_number
View package npm view package_name yarn info package_name
Global install package npm install -g package_name yarn global add package_name

Commands same for npm and yarn:

npm yarn
npm init yarn init
npm run [script] yarn run [script]
npm list yarn list
npm test yarn test
npm link yarn link
npm login or logout yarn login or logout
npm publish yarn publish
Article Tags :