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

In this exercise, you will build out the controller files for each module.

Get Unlimited Access Now

Transcript from the "Exercise 9" Lesson

[00:00:00]
>> [MUSIC]

[00:00:04]
>> Speaker 1: So if you look there is a controller file in each api now and a lot of them are already built out. I forgot that half of them are already built out. You just got to go fill in the bank ones inside the controller files. The subject you are going to be working on, if you are looking at the api folder on each resource there's a respective controller file.

[00:00:27] A lot of the stuff is already built out in there. You only have to fill out maybe two or three for each file. And if you want to get hints on how that works, if you go to the other resources file, it might be filled out in there.

[00:00:38] So just kind of like see what's going on in that file and apply it to the other resource and you'll get a fill. And once you complete this, the actual routes, you need to, actually we're going to save that for later, so yeah. You're not going to be able to test this either, cuz the routes aren't set up.

[00:00:58] If you want to take a step ahead and test it, then you have to connect the routes. Which is fine, you could totally do that. But you still won't be able to test this without setting up the routes.
>> Speaker 1: So yeah, just finish this. We'll come back tomorrow with the solution.

[00:01:16] And then that'll be that. Actually I guess you could test this, you just couldn't test it with the API. You wanna test this you just have to manually run the code. Just like grab this query here and run it. Just make sure you're not calling like next inside of here because that's Express stuff and it would just break, right?

[00:01:36] So just like here's the query and I'm gonna run it. Just like execute it and run the file and it would totally work. Another good way you could do it is if you just make another file in the route here. I'm just gonna make another file and call is dbtest.js.

[00:01:51] And then you could just require the models that you want, and just start building queries in here and just execute this file.
>> Speaker 1: Once you're connected to Mongo. So you could do that, too if you wanted to.