1 00:00:00,620 --> 00:00:04,590 The first thing to do when starting a new Node.js project 2 00:00:04,590 --> 00:00:06,688 is to install the project's dependencies. 3 00:00:06,688 --> 00:00:11,450 Dependencies are third-party Node modules used in your project. 4 00:00:11,450 --> 00:00:15,110 Modules, like Express, give you a lot of power, so 5 00:00:15,110 --> 00:00:19,150 you don't have to write a complete Web application from scratch. 6 00:00:19,150 --> 00:00:24,100 Let's take a look at how to start a new Node project, and install Express. 7 00:00:25,200 --> 00:00:30,340 First things first, I'm teaching this course using three primary applications 8 00:00:30,340 --> 00:00:36,100 on a local machine, a text editor, a terminal or console, and a web browser. 9 00:00:36,100 --> 00:00:39,100 I have my terminal open here, I'm on a Mac. 10 00:00:39,100 --> 00:00:43,220 If you're using Windows, you can use a command prompt, PowerShell, 11 00:00:43,220 --> 00:00:45,590 or other command line utility. 12 00:00:45,590 --> 00:00:49,390 Common free text editors are Visual Studio Code and Atom, but 13 00:00:49,390 --> 00:00:51,530 there are many to choose from. 14 00:00:51,530 --> 00:00:55,070 And you're obviously using a browser since you're taking this course. 15 00:00:55,070 --> 00:00:59,220 In addition to the above applications, you'll need Node and 16 00:00:59,220 --> 00:01:01,750 NPM installed on your local machine. 17 00:01:01,750 --> 00:01:05,160 See the Teacher's Notes for links to installation guides 18 00:01:05,160 --> 00:01:08,600 if you need help installing Node and MPM on your machine. 19 00:01:09,810 --> 00:01:14,410 We'll create all files that we need from scratch as we go through the course. 20 00:01:14,410 --> 00:01:16,090 If you follow along with me, 21 00:01:16,090 --> 00:01:19,160 you should have the same results as you see in the videos. 22 00:01:19,160 --> 00:01:22,600 However, if you want to jump somewhere later on, you can. 23 00:01:22,600 --> 00:01:26,965 Just download the project files and unzip them and find the appropriate folder that 24 00:01:26,965 --> 00:01:30,600 corresponds with the video that you're starting out. 25 00:01:30,600 --> 00:01:32,820 I'd recommend copying that folder and 26 00:01:32,820 --> 00:01:36,390 working with that copy in case you want to start over. 27 00:01:36,390 --> 00:01:41,340 You can always just throw it away and then copy the relevant folder again. 28 00:01:41,340 --> 00:01:45,780 Check the Teacher's Notes for some additional tips using the project files. 29 00:01:45,780 --> 00:01:48,330 Without much further ado, let's begin. 30 00:01:49,380 --> 00:01:53,670 In my terminal, I'll create a directory that will hold the Express application 31 00:01:53,670 --> 00:01:56,160 using the mkdir command. 32 00:01:56,160 --> 00:02:01,440 Let's call the directory flashcards, and open the directory 33 00:02:01,440 --> 00:02:06,500 by using the command cd, and then the directory name, flashcards. 34 00:02:06,500 --> 00:02:13,225 Now, to initialize a Node application, you can use npm init -y. 35 00:02:13,225 --> 00:02:17,340 The -y just accepts all the default options. 36 00:02:17,340 --> 00:02:20,420 Otherwise, you'd have to type them all by hand. 37 00:02:20,420 --> 00:02:23,198 For more on using NPM, check the Teacher's Notes. 38 00:02:23,198 --> 00:02:28,137 With our package.json generated, we can install and save Express. 39 00:02:31,170 --> 00:02:37,889 We'll be using the latest version of Express at the time of recording, 4.15.2. 40 00:02:39,875 --> 00:02:44,830 --save adds this package to the package.json file making it super simple 41 00:02:44,830 --> 00:02:48,170 to install the applications dependencies on another machine. 42 00:02:49,440 --> 00:02:52,320 Now, lets add some code for our application. 43 00:02:52,320 --> 00:02:56,760 Depending on the text editor that you'd like to use, you can usually create 44 00:02:56,760 --> 00:03:00,920 a new file and launch it in the new editor from the command line. 45 00:03:00,920 --> 00:03:07,512 For example, for Atom, you can type atom, and then space, and then the file name. 46 00:03:10,619 --> 00:03:18,630 I prefer Visual Studio code, and its command is code instead of atom. 47 00:03:18,630 --> 00:03:22,850 Check the documentation for your editor if you'd like to use this convenience. 48 00:03:22,850 --> 00:03:27,880 Otherwise, you can simply open the text editor manually and 49 00:03:27,880 --> 00:03:30,547 create a new file from the menu. 50 00:03:30,547 --> 00:03:33,720 I'll type code.app.js. 51 00:03:33,720 --> 00:03:36,504 You can see the new file open in the editor. 52 00:03:36,504 --> 00:03:41,500 App.js will be the main file that holds our Express application. 53 00:03:41,500 --> 00:03:46,293 In order to use Express, we must add it using Nodes require statement. 54 00:03:52,124 --> 00:03:54,179 The module is called Express and 55 00:03:54,179 --> 00:03:57,913 it is the parameter that I pass into the require function. 56 00:04:01,775 --> 00:04:05,790 In this case, Express is also an ideal variable name. 57 00:04:05,790 --> 00:04:10,250 And that is the variable that I will assign the required module to. 58 00:04:10,250 --> 00:04:15,750 From this point on, I can use the variable express to access all the methods and 59 00:04:15,750 --> 00:04:17,730 properties of the Express module. 60 00:04:18,950 --> 00:04:24,950 Great work, Express is installed, imported and ready to be used in our application. 61 00:04:24,950 --> 00:04:28,350 Next, you'll build your first Express application.