1 00:00:00,690 --> 00:00:03,420 Instructor: So, it's time to start writing some code. 2 00:00:03,420 --> 00:00:05,850 I'm in my terminal, in my project directory 3 00:00:05,850 --> 00:00:07,890 which I've called auth. 4 00:00:07,890 --> 00:00:09,600 I'm gonna create a new file in here, excuse me, 5 00:00:09,600 --> 00:00:12,060 a new folder whose sole job is going to be 6 00:00:12,060 --> 00:00:14,430 to hold our API server. 7 00:00:14,430 --> 00:00:16,740 I'm gonna call it server. 8 00:00:16,740 --> 00:00:19,110 So, I'm gonna make my new directory called server, 9 00:00:19,110 --> 00:00:20,560 and then I'll change into it. 10 00:00:22,140 --> 00:00:22,973 Cool. 11 00:00:24,000 --> 00:00:26,190 Now, the thing that I wanna do on this server 12 00:00:26,190 --> 00:00:28,920 is use absolutely no boiler plate, whatsoever. 13 00:00:28,920 --> 00:00:30,150 So, zero boiler plate. 14 00:00:30,150 --> 00:00:32,070 We're gonna do the entire server from scratch 15 00:00:32,070 --> 00:00:34,050 to make sure that we really understand what's going on 16 00:00:34,050 --> 00:00:35,910 from start to finish. 17 00:00:35,910 --> 00:00:38,520 So, to get started with our from scratch server, 18 00:00:38,520 --> 00:00:41,610 the first thing we'll do is create a package.json file 19 00:00:41,610 --> 00:00:44,223 to hold all of our dependencies for our project. 20 00:00:45,150 --> 00:00:47,070 To create a package.json file, 21 00:00:47,070 --> 00:00:49,590 we'll use the npm init command. 22 00:00:49,590 --> 00:00:51,033 So, I'll run npm init. 23 00:00:53,220 --> 00:00:55,590 This is going to prompt us with a series of questions. 24 00:00:55,590 --> 00:00:57,780 Your answer to these questions don't really matter 25 00:00:57,780 --> 00:00:59,670 at this point or anytime soon. 26 00:00:59,670 --> 00:01:01,590 And so, I'm just gonna go ahead and hit enter 27 00:01:01,590 --> 00:01:02,940 to go through each of them. 28 00:01:04,680 --> 00:01:06,060 That's it. 29 00:01:06,060 --> 00:01:08,970 And, I've now got a package.json file 30 00:01:08,970 --> 00:01:11,190 inside of my server directory. 31 00:01:11,190 --> 00:01:13,173 I'm gonna open my code editor now, 32 00:01:16,590 --> 00:01:18,303 and pull it onto the screen. 33 00:01:19,590 --> 00:01:20,423 And cool. 34 00:01:20,423 --> 00:01:22,020 Here's my working directory server, 35 00:01:22,020 --> 00:01:24,660 and I've got my package.json . 36 00:01:24,660 --> 00:01:27,000 Let's go ahead and install a couple of dependencies 37 00:01:27,000 --> 00:01:28,920 just while we're here. 38 00:01:28,920 --> 00:01:30,570 I'm going to install a couple dependencies. 39 00:01:30,570 --> 00:01:32,190 We'll talk about each of them before we use them, 40 00:01:32,190 --> 00:01:33,023 don't worry. 41 00:01:33,023 --> 00:01:35,490 But it'd be really nice just to install them ahead of time. 42 00:01:35,490 --> 00:01:39,030 So, I'm gonna do npm install dash dash save, 43 00:01:39,030 --> 00:01:41,070 and then we're going to install a couple different ones. 44 00:01:41,070 --> 00:01:43,350 So, don't hit enter just yet. 45 00:01:43,350 --> 00:01:45,600 We're going to get express. 46 00:01:45,600 --> 00:01:50,310 We're going to get Mongoose, two Os on Mongoose. 47 00:01:50,310 --> 00:01:52,590 Let's make this a little bit bigger. 48 00:01:52,590 --> 00:01:53,423 There we go. 49 00:01:54,990 --> 00:01:58,260 We'll get Morgan and one more, 50 00:01:58,260 --> 00:02:02,310 body dash parser, like so. 51 00:02:02,310 --> 00:02:04,143 Okay, so let's install these. 52 00:02:04,980 --> 00:02:06,300 This is gonna take a little bit of time, 53 00:02:06,300 --> 00:02:08,400 so we'll just let it do its thing for now. 54 00:02:10,860 --> 00:02:13,230 Back over in our code editor, 55 00:02:13,230 --> 00:02:18,230 I'm going to now create a new file called index.js 56 00:02:18,270 --> 00:02:22,840 and this is going to be the main starting point of 57 00:02:24,150 --> 00:02:25,290 the application. 58 00:02:25,290 --> 00:02:26,940 So whenever we start our server up, 59 00:02:26,940 --> 00:02:28,590 this is gonna be the main starting point. 60 00:02:28,590 --> 00:02:30,743 This is gonna be the first thing to execute. 61 00:02:31,920 --> 00:02:33,750 Let's check our dependencies out. 62 00:02:33,750 --> 00:02:34,983 Looks like we're good. 63 00:02:36,960 --> 00:02:39,660 We've got everything installed at this point. 64 00:02:39,660 --> 00:02:42,270 By default, if I'm using Git, 65 00:02:42,270 --> 00:02:45,060 node modules directory here is going to attempt to- 66 00:02:45,060 --> 00:02:48,630 I'm going to be able to commit it to my GitHub repo. 67 00:02:48,630 --> 00:02:51,570 I don't ever want to commit my node modules directory, 68 00:02:51,570 --> 00:02:56,570 so I'm gonna create a new file called .gitignore. 69 00:02:57,390 --> 00:03:00,840 And I'm gonna add a line in here that says node modules. 70 00:03:00,840 --> 00:03:02,010 And this just tells Git 71 00:03:02,010 --> 00:03:03,420 'Hey, ignore node modules 72 00:03:03,420 --> 00:03:05,040 whenever you're considering files 73 00:03:05,040 --> 00:03:06,807 to add to my Git repository.' 74 00:03:08,550 --> 00:03:11,580 Okay, so we're back inside of index.js here. 75 00:03:11,580 --> 00:03:12,513 Looking good. 76 00:03:14,310 --> 00:03:16,470 The next thing I wanna do is just try to 77 00:03:16,470 --> 00:03:17,303 start our server up. 78 00:03:17,303 --> 00:03:18,180 Let's just see what happens. 79 00:03:18,180 --> 00:03:21,270 I'm gonna run node index.js . 80 00:03:21,270 --> 00:03:23,970 This is how we're going to run our server. 81 00:03:23,970 --> 00:03:25,170 And nothing happens. 82 00:03:25,170 --> 00:03:26,430 Well, what'd you expect? 83 00:03:26,430 --> 00:03:27,510 We don't have any code yet, right? 84 00:03:27,510 --> 00:03:29,100 Nothing happens just yet, 85 00:03:29,100 --> 00:03:30,150 but just so you know, 86 00:03:30,150 --> 00:03:32,040 we can run our server at any time, 87 00:03:32,040 --> 00:03:34,530 by running node space index.js 88 00:03:34,530 --> 00:03:36,230 and that will start our server up. 89 00:03:39,060 --> 00:03:40,740 So, this is off to a good start so far. 90 00:03:40,740 --> 00:03:43,170 Let's go ahead and continue inside the next section 91 00:03:43,170 --> 00:03:45,213 and add some more code to our project.