npm
is the default package manager distributed with Node.js. It has a large library of public and private packages stored in a database called ’emp registry’ that users can access via npm’s command-line client. With the help of npm, users can easily manage dependencies used in a project.
yarn
is also a package manager that was released as an answer to some of npm’s shortcomings. However, yarn relies on the npm registry to provide users access to packages. Since yarn’s underlying structure is based on npm itself, your project structure and workflow doesn’t have to go through major changes if you are migrating to yarn from npm.
Like I mentioned before, yarn provides better functionality over npm in some cases. Unlike npm, it caches every package you download, so you don’t have to redownload it whenever needed.
It also provides better security by verifying the integrity of packages using checksums. It guarantees a package that worked on a certain system will work exactly the same way in any other system.