1 00:00:00,180 --> 00:00:05,650 In this video you're going to create and run your very first note J s script. 2 00:00:05,670 --> 00:00:08,160 Now we're gonna keep it simple for the moment. 3 00:00:08,160 --> 00:00:14,790 This is actually the last video in this little getting setup section in the next section which starts 4 00:00:14,790 --> 00:00:16,020 in the next video. 5 00:00:16,110 --> 00:00:21,660 We'll move on to explore node in detail and we'll start to build out meaningful applications. 6 00:00:21,660 --> 00:00:25,060 For now the goal is to just give us a place to even put our code. 7 00:00:25,140 --> 00:00:28,320 And we're gonna figure out how to run our scripts. 8 00:00:28,440 --> 00:00:33,540 Let's go ahead and kick things off by actually closing down the terminal the terminal or the command 9 00:00:33,540 --> 00:00:38,190 prompt on Windows is not something we're gonna use throughout the rest of the class. 10 00:00:38,190 --> 00:00:44,970 Instead I will be using the integrated terminal built right into visual studio code so we don't have 11 00:00:44,970 --> 00:00:46,950 to switch between windows. 12 00:00:46,950 --> 00:00:52,330 I'm going to close that down and let's just get a bit organized on the left hand side. 13 00:00:52,350 --> 00:00:58,080 I'm gonna put the browser that's where this will stay for the rest of the class and on the right hand 14 00:00:58,080 --> 00:00:58,600 side. 15 00:00:58,620 --> 00:01:01,440 I'm going to put Visual Studio code. 16 00:01:01,500 --> 00:01:07,650 Now the goal is to give us a place to put all of the files and folders will end up creating for our 17 00:01:07,650 --> 00:01:09,500 projects throughout the class. 18 00:01:09,600 --> 00:01:15,300 Right here I'm going to expand the Tree View and you'll notice that there is no folder open so let's 19 00:01:15,300 --> 00:01:17,830 go ahead and create one and then we'll open it. 20 00:01:17,910 --> 00:01:24,510 I'll be using the file explorer for my operating system which is the finder to create a new directory 21 00:01:24,810 --> 00:01:27,920 and you could put that directory wherever you wanted to. 22 00:01:27,930 --> 00:01:30,570 I'm going to put mine right on the desktop. 23 00:01:30,660 --> 00:01:36,540 So right here on the desktop I'll be creating a new folder and I'm going to call this something like 24 00:01:36,540 --> 00:01:38,640 node hyphen course. 25 00:01:38,640 --> 00:01:39,490 Perfect. 26 00:01:39,510 --> 00:01:44,840 This is the location where we're going to put all of the stuff we write in this course. 27 00:01:44,940 --> 00:01:49,020 And this is the folder we're gonna open up in Visual Studio code. 28 00:01:49,110 --> 00:01:54,750 I'm gonna shut down the binder and open up that directory right here on the desktop. 29 00:01:54,750 --> 00:01:57,930 I have my node course folder which I'll double click. 30 00:01:57,930 --> 00:02:03,750 This is going to open up that directory in Visual Studio code which I can see based off of the window 31 00:02:03,750 --> 00:02:06,800 title and the folder title over here. 32 00:02:06,810 --> 00:02:14,100 Now we can actually add files and folders to this directory to build out our projects. 33 00:02:14,110 --> 00:02:18,120 Now as I mentioned we're going to keep things pretty simple in this video. 34 00:02:18,120 --> 00:02:22,630 We're gonna have a one line script just to make sure everything is working correctly. 35 00:02:22,680 --> 00:02:29,010 So let's go ahead and create it right here in the node course folder I'm going to create a brand new 36 00:02:29,010 --> 00:02:31,560 file and we can call this whatever we like. 37 00:02:31,770 --> 00:02:35,620 I'm going to call it something like Hello Dot J S. 38 00:02:35,760 --> 00:02:39,390 Remember no J S isn't a programming language. 39 00:02:39,390 --> 00:02:43,050 In the end of the day all the code we write is javascript code. 40 00:02:43,050 --> 00:02:49,920 So right here I'm using a dot J.S. extension exactly like I would if I was creating JavaScript files 41 00:02:49,950 --> 00:02:55,530 that I intended to run in the browser as the first and only line in this file. 42 00:02:55,530 --> 00:02:59,850 We're going to use console dialog to print a message to anyone who runs the script. 43 00:02:59,970 --> 00:03:03,570 So right here we'll be accessing the console object. 44 00:03:03,570 --> 00:03:10,230 We'll be using the log method on there calling it as a function and passing in a single argument right 45 00:03:10,230 --> 00:03:10,670 here. 46 00:03:10,740 --> 00:03:15,600 That is the string something like Welcome to the class. 47 00:03:15,600 --> 00:03:21,450 Now you should be familiar with all of this since the basics of JavaScript are indeed a pre req for 48 00:03:21,480 --> 00:03:22,250 this class. 49 00:03:22,260 --> 00:03:23,190 And there we go. 50 00:03:23,190 --> 00:03:26,250 We now have a simple node script. 51 00:03:26,280 --> 00:03:29,040 Now you might say hey this really isn't a node script. 52 00:03:29,040 --> 00:03:35,880 This is a regular old JavaScript script but it's important to note that console dot log it's not actually 53 00:03:35,880 --> 00:03:38,190 part of the javascript programming language. 54 00:03:38,190 --> 00:03:40,420 This is always part of the runtime. 55 00:03:40,500 --> 00:03:47,190 Whether that comes from a browser like Chrome or node j s so there's no better time than now to show 56 00:03:47,190 --> 00:03:51,540 you where the node docs live over at node j s dot org. 57 00:03:51,540 --> 00:03:55,230 We have this docs page up top on the left hand side. 58 00:03:55,230 --> 00:03:59,550 I have two API pages for the two versions showing on the home page. 59 00:03:59,610 --> 00:04:02,120 I'll click on mine then down below. 60 00:04:02,130 --> 00:04:08,370 I have a long list of different modules we can work with this one the one that we just use is called 61 00:04:08,490 --> 00:04:09,300 console. 62 00:04:09,300 --> 00:04:11,500 I'm going to expand that and what do we get. 63 00:04:11,550 --> 00:04:15,360 We get all sorts of different ways we can use console and down the list. 64 00:04:15,360 --> 00:04:17,520 We do have the one that we just used. 65 00:04:17,520 --> 00:04:24,630 Console dot log so the documentation for node is a great way to get comfortable with the features and 66 00:04:24,630 --> 00:04:28,730 we'll be referring to it a lot throughout the rest of the class. 67 00:04:28,740 --> 00:04:34,030 Right here though we can see that console dot log is something provided by node. 68 00:04:34,140 --> 00:04:38,160 And if I click that it brings us down to some examples as to how we can use it. 69 00:04:38,160 --> 00:04:44,100 Now let's go ahead and actually run our script to see our little message print to the screen then we'll 70 00:04:44,100 --> 00:04:45,910 be done with this video. 71 00:04:45,930 --> 00:04:50,730 As I mentioned we are going to use the integrated terminal throughout this class and makes it really 72 00:04:50,730 --> 00:04:56,670 easy to run terminal commands from right inside a Visual Studio code and you can find it by going up 73 00:04:56,670 --> 00:05:02,620 to the terminal menu and clicking new terminal also take a moment to note the keyboard shortcut. 74 00:05:02,630 --> 00:05:04,910 I'm a huge fan of keyboard shortcuts. 75 00:05:04,910 --> 00:05:07,600 So for me on a Mac it is control Tilde. 76 00:05:07,700 --> 00:05:11,470 I can just type that from anywhere to crack open a new terminal. 77 00:05:11,510 --> 00:05:12,740 And here I have it. 78 00:05:12,830 --> 00:05:15,680 Now we're already navigated to the correct location. 79 00:05:15,680 --> 00:05:21,400 Here I'm running commands from inside of the node course folder and you should see that as well. 80 00:05:21,470 --> 00:05:25,580 And what we're going to do is use that node command once again. 81 00:05:25,670 --> 00:05:30,550 Now in the past we had used node just like this to run individual statements. 82 00:05:30,650 --> 00:05:32,940 When we have a script we want to execute. 83 00:05:32,990 --> 00:05:36,490 We use space and then we provide that script name. 84 00:05:36,500 --> 00:05:42,970 So right here node space Hello J S matching up with the file name we created. 85 00:05:42,980 --> 00:05:47,540 Now we can actually execute this little node application by hitting enter to run it. 86 00:05:47,540 --> 00:05:48,420 And what do I get. 87 00:05:48,620 --> 00:05:49,730 I get my message. 88 00:05:49,730 --> 00:05:51,740 Welcome to the class printing. 89 00:05:51,740 --> 00:05:53,660 And this is fantastic. 90 00:05:53,660 --> 00:05:55,630 That's where we're going to stop for this one. 91 00:05:55,650 --> 00:06:01,340 We now have a place to put our projects and our project files and we know how to run a node scripts. 92 00:06:01,340 --> 00:06:05,960 So we're done with this video and we're done with this section in the next section. 93 00:06:05,960 --> 00:06:11,930 We're going to dive in and start to learn how to use know j asked to build out back end and server side 94 00:06:11,930 --> 00:06:13,060 applications. 95 00:06:13,070 --> 00:06:15,070 I am beyond excited to get to it. 96 00:06:15,080 --> 00:06:19,030 So let's go ahead and jump into the section introduction for the next one.