Yarn Package Manager Crash Course

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] coding dojo is a programming school that turns beginners into developers in only 14 weeks over 90% of their grads land jobs within three months of graduating often making over seventy K per year to learn more visit coding dojo com or click the link in the description below hey what's going on guys welcome to the yarn crash course this course is for anyone that wants to get started with the yarn package manager' and check out the commands and maybe compare it a little bit to NPM and I'll talk about that in a second but first what is yarn yarn is a JavaScript package manager so it's used to install Java Script packages or modules it was created by Facebook and it's a fast and reliable alternative to NPM or node package manager which comes installed with nodejs okay NPM is the most common used package manager for JavaScript so I do have an NPM crash course which is a little more in-depth than this one so if you're not familiar with NPM I would suggest watching that as well now yarn has a similar syntax to NPM with almost identical functionality the commands are different and that's really the purpose of this course is to get you familiar with those commands it installs packages from the NPM registry so anything that you can install with NPM you can also install with the yarn now if this video was made let's say a year ago we would have a slide that shows you all the reasons why yarn is so much better than NPM and that's one of the reasons I wanted to make this video is because a lot of other yarn videos are outdated because they're comparing it to NPM version 4 and yes yarn was much faster more efficient more secure and some of those things may still apply but not to the magnitude as they as it did with NPM for NPM 5 really took some notes from yarn or just blatantly copied its advantages it's much faster than NPM 4 but with just about all the tests that I've seen even with NPM version 5 yarn is still a little bit faster so it used to be well worth it to switch to yarn for speed but now the difference is much closer MP m5 also added a standardized lock file for a cross pass package compatibility yarn had the yarn lock file and now NP m5 has the package dot lock file and this makes things more reliable and we'll talk more about the lock file later and PM 5 also removed the need to add the - - save to save your packages to your package dot JSON file and this I never saw the the use for that anyway why we had to do that but that was a nice advantage that yarn had is that we could just do yarn add in the package name and we didn't have to add any extra flags to save it to the package dot JSON file but now with NPM 5 we don't have to do that so there are advantages to yarn but the the big reasons why people said use yarn over NPM they're just not as great as they used to be since the release of NPM 5 I believe back in May of 2017 so if you ask me my opinion I just think it boils down to peer preference I personally use NPM I always have but recently I've been using yarn quite a bit because I do like the syntax but I'm not going to say that one is better than the other I think it's just it's all about preference NPM is obviously more common that's a huge plus yarn is a little bit faster that's a plus so it's it's all up to you on what you want to do this video is not a comparison video I just wanted to mention this before we actually get in and look at the commands and the syntax all right so enough with the slides let's go ahead and jump in and get started with the yarn package manager alright so I already have yarn installed on my computer but I just want to go through the ways that you can install it in fact you can install it with NPM yarn actually doesn't recommend it they don't even have it on their installation page something about security and integrity but they most likely just don't want you using NPM so for Mac you can use homebrew so you can use the homebrew package manager you can also install it through Mac ports for Windows there's actually an installer you can download that's what I did or you could use the chocolaty package manager for Windows which I've actually never used and you can also use the scoop command-line installer for Windows and then for Linux obviously you can use your standard package manager if you're on Debian you can use apt-get or whatever whatever package manager for your distribution alright so that's how you would install it now what I'm gonna do is just create a new folder and I'm gonna call it let's just call it yarn test and I'm gonna open that up with vs code and I'm gonna use that as my text editor as well as the integrated terminal which you can open with control backtick okay so from here we're gonna start to run our commands and I don't know if I mention this but all the commands will be in the gist file in the description of this video okay so first thing we're gonna do is we're gonna run yarn - V and that's going to give us the current version you can see I have version 1.3 point 2 installed yours maybe later depending on when you're watching this okay we also have the yarn help command which is going to give us all the different commands that that are available to us now we're going to be going over just about every command except for ones that have to do with publishing your own packages on in the NPM repository that's a little beyond the scope of this of this video we're not going to talk about those next thing we're going to look at is yarn and knit and you'll notice that a lot of these are similar to NPM so this works just like NPM and knit it's going to ask us some questions so our package name yawn test version that's good description we'll just say test app and entry point index J s by default repository you can put your name if you want or the author and the license and if it's private all right and then you'll see that it created a package dot JSON file which looks very similar to what would be created with NPM all right and then you can also add what I'm gonna do is just delete this file we can also add the - why flag so if we say yarn and knit - y that'll just accept all the defaults and quickly create the package.json file okay so what if we want to set a default let's say we want to change the license to is C so what we could do is say yarn config set and we could say in it - license and we want to change it to ISC all right so now if I were to get rid of the package.json file and we were to run yarn and knit and go through this you'll see that for the license the default is now is C okay and if we want to check any config values we can say yarn config get and let's say we want to look at and knit license and it shows us that it's ISC now let's say we want to remove it and put it back to the default which was I believe MIT then we could do yarn config remove in it - license oh I'm sorry it's delete not remove all right so now if we were to go and check it again with get can configure you see that it's back to MIT okay so now let's look at installing packages right now we don't have any packages installed we just have our package JSON file setup so with NPM we would do like NPM install let's say lodash with yarn we're gonna say yarn add lodash okay you can see it's very very quick that happened in point 71 seconds all right let's install another one will install the moment package which has to do with formatting dates and times so we'll say yarn add moment and that'll install it and obviously it gets set to dependencies but there's no need to do - save or anything like that okay we can also install stuff from our package Jason so if I were to go in here and let's go ahead and put in let's say we want to install gulp and we want to install the latest version we could just put an asterisk like that so right now if I save this gulp is not installed if we want to install it or anything that we put manually in here then we would run Yarn install and that's gonna install gulp and any dependencies that it has ok now to remove a package we can say yarn remove and let's remove lo - okay so it'll remove it and it will remove it from our dependencies and let's say we want to install a certain version of a package like lo - right now is for point 17 point 4 let's say we want to install for point seventeen point three for some reason so we can simply say yarn add lodash and we can use the @ symbol and say for dot 17.3 all right so now if we install that you can see that that version is installed now in the NPM crash course I go over this stuff a little more the package.json file and the versioning how that works for instance the carrot symbol which means that it's not going to go past the major version here it'll just update the sub versions and we go over all that so you may want to watch that as well if you don't understand the versioning and all that alright now if we want to find outdated versions of modules that we have installed we can say yarn outdated and if we look down here and it'll show us four lodash in purple it's it's basically telling us there's a later version than what we have installed okay now we can also do outdated and search for a certain package so we could say outdated lodash and that'll just check that package and if we want to upgrade we could say yarn yarn upgrade lodash and that should upgrade let me reload this well it didn't upgrade yarn let's just do yarn upgrade that do it that's weird I'm not sure why that that's doing it maybe if we do yar an upgrade lo - at four point seventeen point four there we go alright so now it's upgraded to four point seventeen point four I thought it would just bring it to the latest version if anyone knows if that's supposed to happen or if I miss something then please let me know alright so let's talk about global modules so if you have any experience with NPM which I'm guessing a lot of you do you know that if you want to install something globally you use the dash G so you would do whoops you would do n PM install dash G and then let's say node Mon which is a module to continuously watch your nodejs applications so with yarn what we do is we use global so yarn Global global add node Mon now with NPM you can do the dash G here or you can do it after with yarn you have to do global right after the yarn command okay so it has to be in this order if you do yarn add global what it's gonna do is it's gonna look for a package called global and try to install that okay so it's very important that you do it this way so we'll go ahead and run that and that will install it globally so that we can access it from anywhere all right now where it installs is well actually there's a command that we can use use to find out where your global packages are installed and that's yarn the global bin okay so you can see I'm on Windows so it's gonna be my users whatever my username app data local yarn bin so let's take a quick look at that it's it's my new materialized course there we want to go to the C Drive and users Brad app data local yarn and bin and there it is so you can see that node montes is installed there alright so let's see what about removing global packages so basically the same as the local except we include global so remember global comes first and then we'll say remove node Mon okay and now if we look back in that folder you can see that the node Mon CMD file is now gone now if you want to list out your packages you could say yarn list okay now it's going to give you all your dependencies and the dependencies of the dependencies for instance you can see all the stuff that we have here and then even if we look in like gulp we're gonna have another node modules folder with more dependencies and you can limit the the depth so we could say for instance yarn pattern yarn list and we could say depth equals zero right oh it's supposed to be - - depth and that'll give us just basically the top layer so what you see here won't give us the the dependencies of dependencies and that works just like NPM okay if we want to check just the dependencies for let's say gulp we could say yarn list and we could say - - pattern and let's say gulp okay so that'll give us just the dependencies for gulp now what I want to do is install a package as a dev dependency so I'm gonna I'm gonna install Gulf but first I'm gonna remove it so I'll say yarn remove gulp okay so that'll take it away and then let's install it as a dev dependency so for that we can say yarn add gulp and we can do - upper case D you can also do - - dev okay but we're gonna do upper case D and there we go so now gulp is added as a development dependency now if we want to remove that even though it's a dev dependency all we have to do is say yarn remove gulp and it'll still remove it from the dev dependencies all right so I mean those are the main things that you're gonna be doing just you know adding packages removing them adding them to dev dependencies things like that but let's talk about some of the the less common things one thing you may have noticed is when we ran yarn and knit it created this yarn dot lock file and basically this is used for to have consistent installs across a machine so it holds exactly which versions of the dependencies that were installed along with the repo link and you yourself don't have to worry about this 99% of the time it's completely managed by yarn there is a command that verifies that the versions of the dependencies in your package.json file matched at the lock file and that's yarn check so if we were to say yarn check and it just tells us success that the folders are in sync so if you ever want to check that then you could do that another thing another command we have is yarn import so for some reason this gets deleted what we can do is we can generate a new yarn lock file from the existing node modules folder so we can say yarn import and now you can see that that created a new lock file okay so what about scripts what about running scripts let's go ahead and clear this out and open up our package.json file and what I'm gonna do here is I'm gonna install node Mon locally as a dev dependency so I'm gonna say yarn add node Mon as a dev whoops as a dev dependency and then I'm gonna add a script so I'm gonna go right here above our dependencies and put in scripts okay set that to an object so make sure you put a comma there and let's say we want a script called dev and we want that to run node Mon and watch the index.js file so we'll save that and then let's create an index J s file and all I'm gonna do here is console dot log hello world and save alright so if we want to run this what we can do is say yarn run dev all right and what it'll do is just constantly watch this file if I were to change this to hello there and save it's gonna watch it it's gonna reload and it's gonna console log hello there alright so yarn run just like NPM run same thing alright you'll notice a lot of similarities another command that is less common that you probably won't use is yarn licenses if you ever want to check the licenses of your packages so we can say licenses and you want to say less and that's just gonna spit out all the different licenses so you can see this rapi dependency as a is C this one has an MIT license BSD 3 clause so if you ever want to check those out you can okay if you want to zip up all your all your packages into a gzip file you can do that with yarn pack so if we say yarn pack and run that notice that now it put this file here called yarn test version 1 0 0 dot tgz okay so created that tarball for us but I'm just going to delete that okay and if you want to check your cache okay you could do yarn cache list and you can see what packages are in the cache alright so you can see we have quite a bit and if you want to clear it out what did i do cache list actually before we clear it out you can check for specific modules with by saying pattern and let's say lodash and it'll just give us the low - stuff you can see here low - keys and template all that stuff and then to clear it we can say yarn cache clean and that will clear it out alright guys so that's gonna be it for this tutorial I will be gone for two days so I probably won't make a video until probably Monday or yeah around Monday or so I'm going to Foxwoods in Connecticut which is a big casino me and my wife usually go maybe two to two or three times a year so wish me luck and that's it I like the video if you liked it and subscribe if you want and I will see you next time hopefully I'll be a richer man in my next video coding dojo is a programming school that turns beginners into developers in only 14 weeks if you're serious about landing a career in tech but lack the formal education or background coding dojo will get you there in no time with over 3,000 graduates to date over 90% of their grads land jobs within three months of graduating often making over 70 K per year at tech firms of all sizes from companies like Google to local startups to learn more visit coding dojo com or click the link in the description below
Info
Channel: Traversy Media
Views: 68,304
Rating: undefined out of 5
Keywords: yarn, yarn js, yarn package manager, yarn npm, yarn packages, yarn tutorial
Id: g9_6KmiBISk
Channel Id: undefined
Length: 22min 43sec (1363 seconds)
Published: Thu Jan 25 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.