1 00:00:00,660 --> 00:00:04,620 So it's time for a five minute crash course of node and JavaScript. 2 00:00:04,650 --> 00:00:09,030 Obviously, that's not enough time to even scratch the surface, but I'm just going to show you the 3 00:00:09,030 --> 00:00:12,930 basics of what you need to know for us to continue on with the course. 4 00:00:13,310 --> 00:00:17,400 OC So back over in Cloud nine, we will delete everything. 5 00:00:17,430 --> 00:00:19,680 Get rid of it so you can do that either. 6 00:00:19,680 --> 00:00:25,170 If you want to use a command line, you could do use arm and dash RF or just. 7 00:00:25,940 --> 00:00:30,350 Highlight what you need to delete right click and where is that delete? 8 00:00:30,530 --> 00:00:32,180 And then we'll say yes to all. 9 00:00:32,180 --> 00:00:35,410 We want to remove all of it and we're home free now. 10 00:00:35,450 --> 00:00:36,920 Can get rid of some of this stuff. 11 00:00:37,610 --> 00:00:38,330 Perfect. 12 00:00:39,080 --> 00:00:40,160 Make some space. 13 00:00:40,160 --> 00:00:41,390 I'll bring this up a bit. 14 00:00:41,750 --> 00:00:45,860 And now all that we're going to do is make our first JavaScript file. 15 00:00:45,860 --> 00:00:47,180 We can call it whatever we want. 16 00:00:47,630 --> 00:00:55,670 You can either use touch apks or you don't have to call it JS or you can right click over here and click 17 00:00:55,670 --> 00:00:57,200 on New File. 18 00:00:57,320 --> 00:01:02,510 I'll do that one and I will call this well I'll do JS. 19 00:01:02,540 --> 00:01:03,650 It's a standard name. 20 00:01:05,200 --> 00:01:07,030 And I won't recreate it down here. 21 00:01:07,060 --> 00:01:11,890 Now we'll open it up, double click, and we'll add some JavaScript in here. 22 00:01:11,980 --> 00:01:16,900 So what I want to show you is this basic workflow with Node that we kind of saw already. 23 00:01:16,930 --> 00:01:24,430 We typed some code in the file, we save it, and then we execute the file with the command node space 24 00:01:24,430 --> 00:01:25,790 and then the name of the file. 25 00:01:25,810 --> 00:01:30,970 So it's very similar, at least in principle, to what we did with the SQL Files, where we would save 26 00:01:30,970 --> 00:01:33,190 a SQL file ending in SQL. 27 00:01:33,220 --> 00:01:40,440 Put something in there, a query, then we would execute it using source and then some file name dot 28 00:01:40,570 --> 00:01:41,380 SQL. 29 00:01:41,560 --> 00:01:42,520 Same idea. 30 00:01:43,360 --> 00:01:45,380 So I'm going to show you some very simple code. 31 00:01:45,400 --> 00:01:46,510 There's something called. 32 00:01:46,690 --> 00:01:49,480 And again, if you know this stuff, feel free to skip it. 33 00:01:50,110 --> 00:01:51,740 Something called console.log. 34 00:01:51,760 --> 00:01:55,310 Kind of the simplest possible command you can do in my SQL. 35 00:01:55,330 --> 00:01:58,600 It will just print something out so we can do our basic. 36 00:01:59,380 --> 00:02:00,130 Hello. 37 00:02:00,160 --> 00:02:01,450 Oops, we don't need caps. 38 00:02:02,650 --> 00:02:03,640 Hello world. 39 00:02:05,700 --> 00:02:10,699 And we'll put a semicolon there, which should seem familiar from my SQL at least. 40 00:02:10,710 --> 00:02:11,940 And let's start with this. 41 00:02:11,940 --> 00:02:14,160 Our first application, very basic. 42 00:02:14,730 --> 00:02:19,980 If all we need to do to execute it is come down here and type node and the name of the file which we 43 00:02:19,980 --> 00:02:22,170 called app dot js. 44 00:02:23,340 --> 00:02:26,670 And it runs silly, but it works. 45 00:02:27,160 --> 00:02:32,370 Okay, so that doesn't seem useful, of course, but it's something, right? 46 00:02:32,370 --> 00:02:39,510 And to see kind of why a programming language would be useful, let's at least do this 500 times. 47 00:02:39,540 --> 00:02:40,080 Let's. 48 00:02:40,080 --> 00:02:43,470 Maybe that's not useful, but we can at least see how it's helpful. 49 00:02:43,470 --> 00:02:47,820 It's doing something that we can't do on our own so we can create a simple loop. 50 00:02:51,170 --> 00:02:53,420 We'll do less than 500. 51 00:02:54,410 --> 00:03:01,970 Now, in my other courses, this is like an entire video, five or 10 minutes with exercises, but I'm 52 00:03:01,970 --> 00:03:03,210 not going to spend time on that. 53 00:03:03,230 --> 00:03:07,760 What this here does is it says whatever's inside of here repeat 500 times. 54 00:03:08,060 --> 00:03:11,360 Basically, this is a counter saying, okay, we're starting at zero. 55 00:03:11,870 --> 00:03:17,030 And every time through the loop we're going to add one to I, which is what this does here. 56 00:03:17,060 --> 00:03:19,400 So we go zero next time around. 57 00:03:19,400 --> 00:03:21,680 One, two, three, keep going. 58 00:03:21,680 --> 00:03:23,660 While it's less than 500. 59 00:03:23,660 --> 00:03:25,490 As soon as it hits 500, we're done. 60 00:03:25,790 --> 00:03:32,450 Okay, so if I just put that in there, whatever is in these brackets here will happen 500 times. 61 00:03:33,530 --> 00:03:33,980 Let's do it. 62 00:03:33,980 --> 00:03:38,270 Now, one thing that I could add that I probably should is this var keyword. 63 00:03:38,900 --> 00:03:41,900 It's just don't worry about it, but it's important to have it there. 64 00:03:43,190 --> 00:03:50,990 Now, if I run it and I scroll up, I can see we get hundreds of hello world's well 500 so imagine you 65 00:03:50,990 --> 00:03:52,580 might be wondering why do you care. 66 00:03:52,610 --> 00:03:59,210 Well, imagine instead of console.log what if we had insert a new user into the database? 67 00:03:59,660 --> 00:04:04,650 That would be a fantastic way to quickly see the database with a bunch of data. 68 00:04:04,670 --> 00:04:07,790 Remember how we had to do this obnoxious copy and paste? 69 00:04:07,790 --> 00:04:09,410 So I would give you a file. 70 00:04:09,440 --> 00:04:10,580 You would copy and paste. 71 00:04:10,790 --> 00:04:16,290 Like for the movies, data and review service, these big files you had to copy and paste it in. 72 00:04:16,310 --> 00:04:18,980 It's an awful way of of getting sample data. 73 00:04:18,980 --> 00:04:21,920 Well, we can use JavaScript to create data for us. 74 00:04:21,920 --> 00:04:24,050 So just a couple other things that I'll show you. 75 00:04:24,620 --> 00:04:31,730 We can do math and basic things like five plus five and I won't do this 500 times. 76 00:04:32,030 --> 00:04:37,390 We can comment things out, selecting them and doing command slash so that won't run anymore. 77 00:04:37,400 --> 00:04:39,770 So now I'm only running five plus five. 78 00:04:40,220 --> 00:04:41,540 You can see we get ten. 79 00:04:41,570 --> 00:04:44,000 One other thing to address is what? 80 00:04:44,000 --> 00:04:47,630 What is Node if you're not familiar with it and it's actually a pretty common question. 81 00:04:47,630 --> 00:04:53,360 There's a bit of confusion about Node Node.js, which is what it's called, and regular JavaScript and 82 00:04:53,360 --> 00:04:54,230 what the difference is. 83 00:04:54,230 --> 00:04:56,450 Basically, JavaScript is a programming language. 84 00:04:56,450 --> 00:04:57,770 It was created first. 85 00:04:58,010 --> 00:05:03,020 It's been around for a while and it's existed as a language that you can use on the client side. 86 00:05:03,020 --> 00:05:10,220 So what that means is that back on this diagram, there's a line right here, not right now, but imagine 87 00:05:10,220 --> 00:05:10,690 a line. 88 00:05:10,700 --> 00:05:12,020 This is the client side. 89 00:05:12,020 --> 00:05:17,540 So I could write JavaScript code that did things over on someone like on my computer. 90 00:05:17,540 --> 00:05:23,240 You could write code that would animate something or make a game or just add some pretty effects. 91 00:05:23,240 --> 00:05:28,490 That's not to say that it's not powerful, but traditionally it was used kind of to decorate pages, 92 00:05:28,490 --> 00:05:31,190 if you will, and it had nothing to do with databases. 93 00:05:31,190 --> 00:05:32,720 It had nothing to do with servers. 94 00:05:32,720 --> 00:05:38,510 You would use another language over here like PHP and you would use JavaScript on the client side of 95 00:05:38,510 --> 00:05:39,230 the front end. 96 00:05:39,350 --> 00:05:47,150 But then Node came around about five years ago now and what it is, is an implementation of JavaScript 97 00:05:47,150 --> 00:05:51,500 written so that you can use it on the back end, so that you can do things like this. 98 00:05:51,500 --> 00:05:57,980 You can create a server with JavaScript instead of having to do it with Ruby or PHP, and it can talk 99 00:05:57,980 --> 00:06:01,280 to a database like any other server side language. 100 00:06:01,280 --> 00:06:04,340 So to summarize that node is JavaScript. 101 00:06:04,790 --> 00:06:11,000 It uses basically the exact same syntax, but you can use it on the back end, which is what we'll be 102 00:06:11,000 --> 00:06:12,290 doing in this course.