This course has been updated! We now recommend you take the API Design in Node.js, v4 course.

Check out a free preview of the full REST & GraphQL API Design in Node.js, v2 (using Express & MongoDB) course:
The "Exercise: Setup Express" Lesson is part of the full, REST & GraphQL API Design in Node.js, v2 (using Express & MongoDB) course featured in this preview video. Here's what you'd learn in this lesson:

Overview of the files involved in the exercise to bootstrap express.

Get Unlimited Access Now

Transcript from the "Exercise: Setup Express" Lesson

>> Scott Moss: So yeah, once you check that out, let me go ahead and check out here, you should have less than one. And then if you take a look around, first of all, take a look around the app if you want. Obviously, there's a lot of stuff here that's gonna be filled out, that way we can progress through the course at a reasonable pace here.

[00:00:12] But if you take a look inside of source index.js, you'll see some stuff here.
>> Scott Moss: Basically, what we're doing here is, and this is something I didn't do on v1, is that we're gonna build this app using Webpack. I know people are thinking, why we using Webpack on the server side?

[00:00:32] Trust me, we're gonna build this app with Webpack. One, that's gonna allow everybody to use the latest features, like imports, ES6 imports, and all the latest and greatest if you're in a different version of node. And two, we can use hot module reloading on the server side, which is pretty cool, which is a way better approach than using something like Nodemon, which just refreshes the server and doesn't keep state.

[00:00:50] So this allows us to keep state in the app. If you have a cache or something like that, it'll just replace the module at runtime if it's there, so we're gonna use that. So you can ignore all this stuff here, we can talk more about how to set up module hot reloading later.

[00:01:07] But basically, what your objective is in the index.js, I want to be able to, this is where I wanna start my server, so this app right here, it's gonna be the server. This is gonna be the express app that I showed here, this is the express app, and you see I'm listening to it on port 3000.

[00:01:28] Inside of here, I wanna go ahead and actually start that server. This app is gonna be that express app, so that's what I wanna do. And then inside of server.js, we actually need to make app something. Right now it's just null, it's literally nothing, so we need to make it an express app.

[00:01:44] So if you look at the example that I have here, you can see how one might go about doing that. But basically, app needs to be an express app. Go ahead and set up a Hello World Route on index that does something so you can at least check it out.

>> Scott Moss: And then you need to go ahead and listen to that server inside of index, somewhere here, whatever port you want, whatever port you have open. There are some ports you can't use, but you'll figure it out if you type it in, [LAUGH] and that's all this example is.

[00:02:17] So what we're gonna do is, what time is it now, it's almost 10, so let's say, this one's not gonna take too long, so let's come back at 10:15. And then we'll go over it, cool, I'll leave this up here.