1 00:00:00,240 --> 00:00:06,090 In this video you're going to learn how to install and work with global NPM packages. 2 00:00:06,120 --> 00:00:10,620 These are going to allow us to get a new command we can execute from the terminal. 3 00:00:10,620 --> 00:00:16,030 So far all of the packages we've worked with are known as locally install the packages. 4 00:00:16,050 --> 00:00:21,930 That's when we install the dependency explicitly into our project like we've done with validator and 5 00:00:21,930 --> 00:00:24,560 chuck in the notes app project. 6 00:00:24,570 --> 00:00:28,560 You can tell it's a local dependency because it's listed in package. 7 00:00:28,620 --> 00:00:36,540 Jason like our two dependencies are now local NPM modules those get loaded into your project code with 8 00:00:36,540 --> 00:00:43,410 require like we've seen with chalk and validator when we install a module globally we actually don't 9 00:00:43,410 --> 00:00:49,800 load it indirectly to our source files instead we install it globally and it gives us access to a new 10 00:00:49,800 --> 00:00:52,390 command we can use from the terminal. 11 00:00:52,440 --> 00:00:59,340 Now in the case of this video we're going to install a NPM module globally that is a really nice utility 12 00:00:59,340 --> 00:01:05,310 for working with node because it's going to allow us to run our application and automatically restart 13 00:01:05,370 --> 00:01:08,210 the app whenever the app code changes. 14 00:01:08,310 --> 00:01:13,820 So I can make a change up above and save the file and will immediately see the results down below. 15 00:01:13,890 --> 00:01:19,710 So we won't have to constantly switch to the terminal and rerun the same command over and over again 16 00:01:19,830 --> 00:01:25,650 we can find the package we're going to install by heading over to NPM and J ask.com and going up to 17 00:01:25,650 --> 00:01:28,110 that search bar once again right here. 18 00:01:28,150 --> 00:01:33,660 The package we're gonna use is called a Node mine and is n o d e m o n. 19 00:01:33,810 --> 00:01:39,300 Right here the first result is the package we're looking for and I'm just showing you where this package 20 00:01:39,420 --> 00:01:41,890 lives in case you want to learn more about it. 21 00:01:41,910 --> 00:01:44,790 It's actually a very easy tool to use. 22 00:01:44,790 --> 00:01:46,820 So let's just get right to it. 23 00:01:46,860 --> 00:01:52,800 The first thing we have to do is install it now when we're installing a module globally the Installation 24 00:01:52,800 --> 00:01:56,490 Command is basically the same with one slight difference. 25 00:01:56,490 --> 00:01:58,930 So let's go ahead and get started down below. 26 00:01:59,100 --> 00:02:07,680 We are going to run a command npm install the module name that's node man at one point eighteen point 27 00:02:07,680 --> 00:02:13,400 five and this is the exact format you'd expect if we were to install the module locally. 28 00:02:13,410 --> 00:02:18,150 The only difference is we use the G flag which is short for global. 29 00:02:18,180 --> 00:02:22,130 This is going to install the module globally instead. 30 00:02:22,140 --> 00:02:26,420 Now let's go ahead and run this command and see what happens when the command finishes. 31 00:02:26,520 --> 00:02:33,180 We're gonna notice that node modules package lock Jason and package Jason haven't changed in any way 32 00:02:33,180 --> 00:02:39,570 what so ever when we install a module globally it is not changing the individual project it's installing 33 00:02:39,570 --> 00:02:42,450 the tool on our operating system itself. 34 00:02:42,810 --> 00:02:46,260 So right here it is going through the process of getting everything set up. 35 00:02:46,290 --> 00:02:47,300 Now we're done. 36 00:02:47,370 --> 00:02:48,770 And if I open up package. 37 00:02:48,870 --> 00:02:54,190 Jason what don't we see we don't see node man listed as a dependency. 38 00:02:54,480 --> 00:03:01,020 So it's not something we would ever require in our project and then actually try to use this particular 39 00:03:01,020 --> 00:03:04,000 package wasn't designed to be used like that. 40 00:03:04,290 --> 00:03:09,750 Instead what we got access to was a brand new command from the terminal. 41 00:03:09,750 --> 00:03:14,680 Now when you install an NPM package globally things can indeed go wrong. 42 00:03:14,700 --> 00:03:20,160 I usually get a ton of questions related to this since everyone's environment is slightly different. 43 00:03:20,160 --> 00:03:27,150 If you are running on Linux or Mac and you're getting an error I recommend putting sudo that's S U D 44 00:03:27,210 --> 00:03:30,650 O in front of the command to run it as an administrator. 45 00:03:30,750 --> 00:03:39,360 So that would be pseudo npm install node man at one point eighteen point five with the G flag if you're 46 00:03:39,360 --> 00:03:44,100 on Windows and you're getting some sort of error just crack open a question and of course if you want 47 00:03:44,100 --> 00:03:50,850 a and I'll work with you to get unstuck and back on track we can always verify that node man was installed 48 00:03:50,850 --> 00:03:58,230 correctly by running node man the package name exactly followed by the V flag exactly like we've done 49 00:03:58,230 --> 00:04:04,830 with node and with NPM when I run it what do I get I'll get a version one point eighteen point five 50 00:04:04,860 --> 00:04:11,760 the exact one I specified in my installation command this is Andrew from the future with a quick update 51 00:04:11,940 --> 00:04:16,980 if you're running on Windows and you're using power shell as your terminal the command that we just 52 00:04:16,980 --> 00:04:21,620 ran to check the node man version might have failed so you might be seeing the error. 53 00:04:21,630 --> 00:04:23,510 That's right up top when I run. 54 00:04:23,520 --> 00:04:30,060 No demon with the V flag I get the following error saying that no demand can not be loaded because running 55 00:04:30,060 --> 00:04:34,800 scripts is disabled on this system so if you're running into that don't worry. 56 00:04:34,800 --> 00:04:36,570 There are a couple of fixes. 57 00:04:36,630 --> 00:04:42,630 The first thing you could do is use the regular command prompt application instead of using power shout 58 00:04:43,020 --> 00:04:45,430 if you'd like to continue using power shell. 59 00:04:45,510 --> 00:04:47,940 You can work through the four steps down below. 60 00:04:47,970 --> 00:04:52,170 So step one click on the windows icon and search for power shell. 61 00:04:52,170 --> 00:04:57,680 Step Two right click power shell in these search results and click Run as Administrator. 62 00:04:57,750 --> 00:05:04,290 Once you have it running as an administrator in step three run set execution policy setting and equal 63 00:05:04,290 --> 00:05:09,000 to unrestricted spacing and the capitalization is important. 64 00:05:09,000 --> 00:05:14,740 Once you run that command you should be able to move on to Step Four and to rerun no demand with the 65 00:05:14,760 --> 00:05:21,120 VA flag and instead of getting the error up above you should indeed get the version installed. 66 00:05:21,120 --> 00:05:25,060 So this is a fix for Windows users using power shell. 67 00:05:25,080 --> 00:05:31,760 All right let's jump right back in to the lesson if you're seeing a version that's great if you're not. 68 00:05:31,760 --> 00:05:36,650 That means once again something went wrong and you can always crack open a question in the Q and A and 69 00:05:36,650 --> 00:05:41,060 we'll work with you to get new global modules working correctly. 70 00:05:41,060 --> 00:05:46,580 So we have access to this new node man command and the question is how exactly do we use it. 71 00:05:46,850 --> 00:05:48,040 Well let's explore that. 72 00:05:48,080 --> 00:05:54,710 First up I am going to clear the terminal output to make things a bit easier to read and all we do is 73 00:05:54,710 --> 00:05:59,810 we run our script like we would have with node but we change the command we're using. 74 00:05:59,810 --> 00:06:06,450 So in the past we use node space at DOT J S to run the script once with node man. 75 00:06:06,530 --> 00:06:14,030 We use node Mun space app dot J S so the only thing we've changed is we've swapped out node for node 76 00:06:14,030 --> 00:06:14,800 man. 77 00:06:14,810 --> 00:06:20,260 Now if we run it we're gonna see our script run with a few additional pieces of output. 78 00:06:20,360 --> 00:06:22,400 Right here we can see it starting node man. 79 00:06:22,400 --> 00:06:27,470 And it lists the version as well as some other logs saying that things are getting started. 80 00:06:27,530 --> 00:06:34,040 Then we do indeed see these two lines that come from our script down below we can see that the program 81 00:06:34,040 --> 00:06:38,300 has exited and it's waiting for changes before it restarts. 82 00:06:38,300 --> 00:06:42,830 So now node mine is up and running and you'll notice it's not bringing us back to the command prompt 83 00:06:42,860 --> 00:06:49,190 even though our program has finished the node mind process is still executing and if we change something 84 00:06:49,190 --> 00:06:54,680 up above we'll see that change instantly printed below when we save the file. 85 00:06:54,680 --> 00:07:01,010 So I'm gonna change chalk dot green over to chalk dot read and then I'm gonna change the message from 86 00:07:01,010 --> 00:07:03,070 success to error. 87 00:07:03,170 --> 00:07:09,110 If I go ahead and save the program down below I can see that basically instantly node mine restarted 88 00:07:09,110 --> 00:07:12,760 the script and now we see the new output from our program. 89 00:07:12,800 --> 00:07:18,530 We're still getting the your notes message and now we're seeing our error shown in red. 90 00:07:18,530 --> 00:07:23,420 We could continue to make changes to our program and see those changes instantly reflected. 91 00:07:23,420 --> 00:07:29,330 I'll switch this to blue save the program and before I'm even done saying I saved it Blue is showing 92 00:07:29,330 --> 00:07:30,650 up down below. 93 00:07:30,650 --> 00:07:35,900 So throughout this class I will be using Node mine and I also use it with my client projects. 94 00:07:35,900 --> 00:07:42,160 So we don't have to constantly restart the node script every single time we make a small change. 95 00:07:42,200 --> 00:07:47,390 It is a great utility just to improve your overall developer experience. 96 00:07:47,390 --> 00:07:53,090 Now if you want to stop node man you can do that by going to the terminal and using control see that's 97 00:07:53,090 --> 00:07:58,730 going to terminate the node and process and bring us back to the command prompt where we can do something 98 00:07:58,730 --> 00:08:05,150 else like install a new module maybe run the script once with node or maybe restart it with node mine 99 00:08:05,270 --> 00:08:06,120 in the future. 100 00:08:06,140 --> 00:08:11,660 All right that's where we're going to stop for this video and that is also the end of this section on 101 00:08:11,660 --> 00:08:13,650 the Node modules system. 102 00:08:13,940 --> 00:08:21,620 You now know how to load in core node modules how to load in your own files and how to load in NPM modules. 103 00:08:21,620 --> 00:08:26,420 This is gonna give us a foundation for the rest of the class where we're gonna do those things over 104 00:08:26,420 --> 00:08:29,150 and over again in the next section. 105 00:08:29,210 --> 00:08:34,250 We're gonna start to explore command line arguments and the file system and we're actually going to 106 00:08:34,250 --> 00:08:37,460 work to build out that notes application. 107 00:08:37,490 --> 00:08:38,900 I am excited to get to it. 108 00:08:38,960 --> 00:08:43,040 So let's go ahead and jump right in into the section introduction for the next one.