NPM vs Yarn Cheatsheet

Moving between projects that use NPM and Yarn typically isn’t a big deal. For the most part, the package dependency managers work almost identical. But one thing that does tend to trip developers up is the subtle command line changes between the two. Often it’s just the case of swapping install/uninstall in NPM to add/remove in Yarn, so here’s a quick cheatsheet for doing just that.

NPM CommandYarn CommandDescription
npm install [package-name]yarn add [package-name]Installs a package
npm install [package-name] –save-devyarn add [package-name] –devInstalls a package as a dev dependency
npm installyarn OR yarn installInstalls all dependencies inside package.json
npm uninstall [package-name]yarn remove [package-name]Uninstalls a package
npm uninstall [package-name] –save-devyarn remove [package-name]Uninstalls a package as a dev dependency (Yarn command is the same as uninstall regular dependency)
npm updateyarn upgradeUpdates all packages
npm update [package-name]yarn upgrade [package-name]Updates a single package
npm install [package-name] -gyarn global add [package-name]Installs a globally accessibly package
npm uninstall [package-name] -gyarn global remove [package-name]Uninstalls a globally accessibly package

While the above are the main commands that have subtle differences. There are actually some commands that are identical between NPM and Yarn, that you basically just sub out the word npm with yarn on the command line and you are good to go. These are :

NPM CommandYarn CommandDescription
npm install –productionyarn install –productionInstalls all dependencies in package.json *except* dev dependencies
npm inityarn initCreates a new package.json file / project setup
npm runyarn runRuns scripts from your package.json file
npm testyarn testRuns tests from your package.json file
npm publishyarn publishPublishes your package/td>
npm cache cleanyarn cache cleanClears the global package cache
npm loginyarn loginLogs a user into an package register

Leave a Reply

Your email address will not be published. Required fields are marked *