1 00:00:00,240 --> 00:00:05,370 In this video which is the last one for this section we're going to make our lives a little bit easier 2 00:00:05,400 --> 00:00:09,630 by setting up a second script and package Jason inside of there. 3 00:00:09,630 --> 00:00:15,510 Right now we have a single script these start script we've created this start script because of that 4 00:00:15,720 --> 00:00:21,270 is what Heroku is looking for when it starts up our application and we learned we could always run that 5 00:00:21,270 --> 00:00:23,670 locally using NPM runs start. 6 00:00:23,700 --> 00:00:30,180 Should we want to in this video we're going to create a second script a development script which is 7 00:00:30,180 --> 00:00:32,700 going to run that node man command. 8 00:00:32,700 --> 00:00:38,250 So currently when we want to start up our server using Node man we have to type out the command from 9 00:00:38,250 --> 00:00:44,940 the terminal every single time that is node man followed by the path to the file source forward slash 10 00:00:45,000 --> 00:00:45,850 app dot J. 11 00:00:45,840 --> 00:00:48,420 S followed by our list of extensions. 12 00:00:48,420 --> 00:00:50,750 J.S. comma HB S.. 13 00:00:50,880 --> 00:00:55,290 We have to type that out every single time we want to start up the application. 14 00:00:55,350 --> 00:00:59,000 It would be much nicer to break that out into a package. 15 00:00:59,040 --> 00:01:05,550 Jason script which we can use and reuse the first step to get this done is to simply define that new 16 00:01:05,550 --> 00:01:06,140 script. 17 00:01:06,150 --> 00:01:12,270 So just after start or before the order does not matter we're gonna set up a second property on these 18 00:01:12,270 --> 00:01:13,740 scripts object. 19 00:01:13,740 --> 00:01:15,690 We can pick a name for the script. 20 00:01:15,690 --> 00:01:21,660 I'm gonna call this Dev which is short for development and we can also pick the actual command to run 21 00:01:21,870 --> 00:01:22,500 here. 22 00:01:22,590 --> 00:01:26,280 We're gonna type out exactly what we just typed out in the terminal. 23 00:01:26,280 --> 00:01:27,890 That is node man. 24 00:01:27,940 --> 00:01:30,600 Source forward slash app dot J. 25 00:01:30,620 --> 00:01:35,360 S with our list of extensions J.S. and h b s. 26 00:01:35,520 --> 00:01:41,030 So with this script in place it's gonna be a lot easier for folks to start up the dev server. 27 00:01:41,100 --> 00:01:47,130 It's gonna be easier for us to rerun the command something we've had to type out so far and as we collaborate 28 00:01:47,130 --> 00:01:53,250 with others they'll be able to use the dev script as well to start up that local development server 29 00:01:53,280 --> 00:01:58,470 easily otherwise they'd have to figure out exactly what's needed and then have to go through that whole 30 00:01:58,470 --> 00:02:04,650 problem of figuring out they need to add the HP s extension as well if there's a command we're using 31 00:02:04,680 --> 00:02:09,420 often in a project it's best to create a script that runs it. 32 00:02:09,480 --> 00:02:13,620 So it's reusable and accessible to everyone even if it's just you. 33 00:02:13,620 --> 00:02:19,200 It's nice to be able to reuse that script without typing things out again from the terminal we can now 34 00:02:19,200 --> 00:02:22,960 go ahead and run that Dev script and see what happens down below. 35 00:02:22,980 --> 00:02:28,680 I'll use control C to shut down the old process where we manually type things out and they'll start 36 00:02:28,680 --> 00:02:32,450 up that Dev script NPM run Dev. 37 00:02:32,520 --> 00:02:36,990 When I started up what's going to happen it's going to print the exact same thing it was just printing 38 00:02:36,990 --> 00:02:38,240 before here. 39 00:02:38,250 --> 00:02:44,010 Node man is starting and it is starting watching for the extensions that we listed out up above and 40 00:02:44,010 --> 00:02:47,350 we can see that by refreshing local host three thousand. 41 00:02:47,550 --> 00:02:50,730 Right here we are still getting the application. 42 00:02:50,730 --> 00:02:57,330 Now if I was to go into one of the j s files like forecast J S and I was to save the file even if I 43 00:02:57,330 --> 00:02:58,790 don't make any changes. 44 00:02:58,860 --> 00:03:04,320 We can see that down below the server did indeed Restart which is fantastic. 45 00:03:04,320 --> 00:03:09,240 Now that we have this in place it's time to talk about the one catch to this solution. 46 00:03:09,240 --> 00:03:15,900 The only reason the devs script works is because we have node man installed as a global module when 47 00:03:15,900 --> 00:03:18,110 we have global modules installed. 48 00:03:18,120 --> 00:03:21,750 It's difficult for other people to know they need to install them. 49 00:03:21,750 --> 00:03:25,480 The problem with global modules is that they're not local dependencies. 50 00:03:25,590 --> 00:03:31,350 So if we're using them in a specific project it's best to try to install everything locally. 51 00:03:31,350 --> 00:03:34,230 So imagine if I gave this project to someone else. 52 00:03:34,290 --> 00:03:37,940 Let's say I push this up to a public get Hub Repository. 53 00:03:37,980 --> 00:03:40,230 Someone decides they want to add a new feature. 54 00:03:40,260 --> 00:03:43,890 I say Yeah go for it and I will integrate that into my project. 55 00:03:43,890 --> 00:03:48,800 So they download the code and they don't get node modules because that's ignored with get ignore. 56 00:03:48,870 --> 00:03:49,790 And that's fine. 57 00:03:49,860 --> 00:03:55,470 They'll be able to run npm install it will dig through the Jason files and it'll get all the modules 58 00:03:55,470 --> 00:04:01,120 installed node modules will get generated for them on their machine and will have express. 59 00:04:01,180 --> 00:04:04,170 It'll have HB Yes and it'll have request. 60 00:04:04,170 --> 00:04:10,320 The problem is that when they go to use that Dev script it's gonna fail because well our project technically 61 00:04:10,320 --> 00:04:12,090 depends on Node Mohn. 62 00:04:12,120 --> 00:04:16,250 It does not have it as a dependency and that is a problem. 63 00:04:16,260 --> 00:04:20,820 Now it might not take too much effort for someone to realize they have to install a node mod but it 64 00:04:20,820 --> 00:04:23,790 would be nice if our app just worked right out of the box. 65 00:04:23,790 --> 00:04:28,230 It's also trickier when different versions expect to be used in different ways. 66 00:04:28,240 --> 00:04:31,320 This might not work with the version they have installed. 67 00:04:31,320 --> 00:04:36,390 And if we don't tell them what version we have installed they really are helpless to solve the issue. 68 00:04:36,390 --> 00:04:37,770 They're running against. 69 00:04:37,770 --> 00:04:44,700 So the solution is to uninstall node Mohn globally and to install it as a local dependency so down below 70 00:04:44,700 --> 00:04:50,160 from the terminal we can use control C to shut down the node demand process and we're gonna go ahead 71 00:04:50,190 --> 00:04:56,430 and run NPM uninstall to uninstall something we're on installing a global module. 72 00:04:56,460 --> 00:05:03,160 So we use that G flag and the name is node my now when we run this it's going to remove node mod which 73 00:05:03,160 --> 00:05:08,930 means we can no longer run it from the terminal and our script is no longer going to work. 74 00:05:08,950 --> 00:05:12,270 Both of them are expecting that command to be available. 75 00:05:12,490 --> 00:05:18,790 We can address this now by installing it as a local dependency something that's actually listed in package 76 00:05:18,820 --> 00:05:27,930 dot Jason right here npm install we are going to install no demand at the version we had before. 77 00:05:27,930 --> 00:05:33,260 One point to point zero and from here we're going to provide a new flag. 78 00:05:33,270 --> 00:05:38,090 Something we haven't used before that is hyphen hyphen save hyphen. 79 00:05:38,090 --> 00:05:45,490 Def when we install something and we use save Dev it lists it as a dev dependency in our project. 80 00:05:45,510 --> 00:05:48,590 So here under package dot Jason we have dependencies. 81 00:05:48,630 --> 00:05:55,110 We have expressed HB s and request and we have Dev dependencies and for this we just have no demand 82 00:05:55,470 --> 00:05:59,780 Dev dependencies our dependencies you only need on your local machine. 83 00:05:59,790 --> 00:06:06,030 Well you're developing these dependencies aren't installed in your production environment which means 84 00:06:06,030 --> 00:06:13,470 that node mine is not installed on Heroku and that's OK Heroku never uses the dev script Heroku just 85 00:06:13,470 --> 00:06:18,220 uses that start script by adding node man as a dev dependency. 86 00:06:18,270 --> 00:06:23,440 We're saving time preventing Heroku from having to install things it's not going to use. 87 00:06:23,520 --> 00:06:29,520 You could easily install this as a regular dependency and the application would still work like it's 88 00:06:29,520 --> 00:06:30,660 working now. 89 00:06:30,720 --> 00:06:35,760 The only difference by breaking it out into a dev dependency is that it's not installed on the production 90 00:06:35,760 --> 00:06:39,320 environment which once again just saves us a little bit of time. 91 00:06:39,330 --> 00:06:45,120 Now the module is installed locally which means that we actually don't have access to it as a straight 92 00:06:45,120 --> 00:06:46,890 up command from the terminal. 93 00:06:46,890 --> 00:06:52,410 So if we were to cycle through our previous commands and get to that node mod command we've run maybe 94 00:06:52,410 --> 00:06:55,360 30 times in the class and actually execute it. 95 00:06:55,440 --> 00:06:56,420 It's going to fail. 96 00:06:56,640 --> 00:07:00,680 It's looking for node man and Node man is not globally installed. 97 00:07:00,690 --> 00:07:02,620 Now our script is still going to work. 98 00:07:02,700 --> 00:07:07,040 Scripts they can use commands from a locally installed modules. 99 00:07:07,050 --> 00:07:13,400 So here it is perfectly valid to use node man because node man is installed as a dependency. 100 00:07:13,410 --> 00:07:18,930 It's OK to use it even though it would fail if we just straight up ran this command from the terminal. 101 00:07:18,960 --> 00:07:23,250 So this is the difference between globally installed and locally installed modules. 102 00:07:23,250 --> 00:07:28,670 Once again the main problem with those globally installed modules is that other people aren't going 103 00:07:28,670 --> 00:07:32,250 to know what modules and what module versions you're using. 104 00:07:32,250 --> 00:07:36,930 By bringing things in as local dependencies anyone can run npm install. 105 00:07:36,990 --> 00:07:42,420 They can have everything installed then they can start working on the project now from the terminal 106 00:07:42,540 --> 00:07:45,700 just to make sure things are working for the final time. 107 00:07:45,720 --> 00:07:49,320 We're going to run NPM run Dev when we do this. 108 00:07:49,320 --> 00:07:53,120 Things are going to work as expected it's able to start up node man. 109 00:07:53,220 --> 00:07:59,430 And if I refresh local host three thousand we can see that our server is indeed up and running. 110 00:07:59,430 --> 00:08:01,950 So that's where we're going to stop before this video. 111 00:08:01,950 --> 00:08:03,150 And that's where we're gonna stop. 112 00:08:03,150 --> 00:08:07,860 For this section in this section you learned about get for version control. 113 00:08:07,860 --> 00:08:13,050 You learned about github for managing your software development projects and you learned how to use 114 00:08:13,050 --> 00:08:16,800 Heroku to deploy your applications to production. 115 00:08:16,800 --> 00:08:21,450 That's where we're going to stop for the section and it's also where we're going to stop for the weather 116 00:08:21,450 --> 00:08:27,060 application in the next section we'll move on to our next application and we're going to kick things 117 00:08:27,060 --> 00:08:32,020 off by talking about how we can connect to real databases from node j. 118 00:08:32,020 --> 00:08:34,390 S I'm very excited to get to that. 119 00:08:34,410 --> 00:08:37,280 So let's go ahead and jump right in to the next one.