Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 8, 2022 04:18 pm GMT

The difference between NPM and Yarn

What is Package Manager?

A package manager is a tool to create project environments and easily import external dependencies. By using a package manager we could able to automates the process of installing, upgrading, configuring, and removing the dependencies from the project environment.

What is NPM?

NPM is commonly known as node package manager, maintained by NPM, Inc. NPM is the popular package manager among JavaScript developers. It is the default package that is automatically installed whenever we install Node.js on our system. (https://www.npmjs.com/)

What is Yarn?

Yarn package manager developed in 2016 by Facebook. It is a another package manager for the JavaScript programing language. Yarn provides speed, consistency, stability, and security as an alternative to NPM.(https://yarnpkg.com/)


Speed

The main difference between NPM and Yarn is the package installation process. Yarn installs packages in parallel. Yarn is optimized to fetch and install multiple packages at once.

NPM will perform a serial installation process. It install every package independently.

So in this case Yarn has a speed installation process than NPM.

Security

NPM package manager has perform a security check on each install. Yarn checks behind the scenes to ensure you're not downloading any rogue scripts and other files that can conflict with your project's dependencies. Security is one of Yarns core features.

Ease of use

NPM and Yarn both package managers are user-friendly and have a good user experience.


Basic Commands

To see list of commands:
NPM - npm
Yarn - yarn

Install dependencies from package.json:
NPM - npm install
Yarn - yarn

Install a package and add to package.json:
NPM - npm install package --save
Yarn - yarn add package

Install a devDependency:
NPM - npm install package --save-dev
Yarn - yarn add package --dev

Remove a dependency:
NPM - npm uninstall package --save
Yarn - yarn remove package

Upgrade a package to its latest version:
NPM - npm update --save
Yarn - yarn upgrade

Install a package globally:
NPM - npm install package -g
Yarn - yarn global add package


Original Link: https://dev.to/samithawijesekara/the-difference-between-npm-and-yarn-2j3p

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To