首页 > 其他分享 >Difference between npm and yarn

Difference between npm and yarn

时间:2022-09-23 17:45:47浏览次数:88  
标签:npm package lock yarn project dependencies Difference

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

  • npm: npm is installed with Node automatically.
  • yarn: To install yarn npm have to be installed.
    npm install yarn --global

The lock file

  • npm: NPM generates a ‘package-lock.json’ file. The package-lock.json file 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 log

  • install: The npm creates massive output logs of npm commands. It is essentially a dump of stack trace of what npm is doing

 

add: The yarn output logs are clean, visually distinguishable and brief. They are also ordered in a tree form for understandability.

 

Installing global dependencies

  • npm: To install a global package, the command template for npm is:
    npm install -g package_name@version_number
  • yarn: To install a global package, the command template for yarn is:
    yarn global add package_name@version_number

The ‘why’ command:

  • npm: npm yet doesn’t has a ‘why’ functionality built in.
  • yarn: Yarn comes with a ‘why’ command that tells why a dependency is present in the project. For example, it is a dependency, a native module, or a project dependency.

License Checker

  • npm: npm doesn’t has a license checker that can give a handy description of all the licenses that a project is bound with, due to installed dependencies.
  • yarn: Yarn has a neat license checker. To see them, run
yarn licenses list

 

Fetching packages

  • npm: npm fetches dependencies from the npm registry during every ‘npm install‘ command.
  • Yarn: yarn stores dependencies locally, and fetches from the disk during a ‘yarn add‘ command (assuming the dependency(with the specific version) is present locally).

 

标签:npm,package,lock,yarn,project,dependencies,Difference
From: https://www.cnblogs.com/chucklu/p/16723560.html

相关文章

  • npm install -D 和 - S,--save 和 --save--dev 到底是什么意思?
    前言用过npm安装各种包的小伙伴肯定对下面安装命令烂熟于心npminstall'要安装的包'-Snpminstall'要安装的包'-Dnpminstall'要安装的包'--savenpminstall......
  • CentOS 7/8 搭建 Node.js 环境及npm包管理器
     服务器环境:LinuxCentOS7或CentOS8系统=====================================使用EPEL源安装1、下载并安装EPEL源,终端命令如下:1sudorpm-ihttp://download......
  • 使用 PNPM 将 React App 中的磁盘空间减少 60%
    使用PNPM将ReactApp中的磁盘空间减少60%在React应用程序中使用PNPM减少磁盘空间的教程。Photoby诺德伍德主题on不飞溅您是否正在处理具有共同依赖项的......
  • mapreduce和yarn集群
    mapreduce: 先分再合,分而治之      分布式计算概念:计算方式,与集中式计算相对。将应用拆分成小的部分,分配给多台计算机处理,mapreduce是分布式的计算框架。......
  • 出现yarn启动项目失败
    $yarnrunserveyarnrunv1.22.19$vue-cli-serviceserve'vue-cli-service'不是内部或外部命令,也不是可运行的程序或批处理文件。errorCommandfailedwithexit......
  • 在控制台使用npm init vue@latest命令报错npm ERR! Error: EPERM: operation not perm
    问题描述:    在控制台中输入npminitvue@latest命令创建vue3项目,按照流程一步一步走,   结果发现报错npmERR!Error:EPERM:operationnotpermitted,......
  • nodeJs + npm 环境搭建
    目录1、安装nodeJS2、配置系统环境变量PATH=nodejs安装目录3、在nodejs安装根目录创建node_cache、node_global两个文件夹4、配置npm5、查看配置是否生效(win+R启动终端......
  • Yarn使用ZK做高可用
    1. 目前可用的YARN resourceManager状态存储实现类有如下三个:org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore#aZooKeeperbasedstate-st......
  • npm yarn 报错
    目录npmyarn报错yarn:无法加载文件npmyarn报错yarn:无法加载文件win10系统,yarn:无法加载文件C:\Users\丽丽小可爱\AppData\Roaming\npm\yarn.ps1,因为在此系统上......
  • 切换 yarn 源地址
    yarn默认的源是:https://registry.yarnpkg.com。对于国内的程序员来说实在是太慢了,得换淘宝源地址:PSE:\DevProjects\WebProjects\app>yarnconfigsetregistryhttps:......