This course has been updated! We now recommend you take the API Design in Node.js, v4 course.
Transcript from the "Exercise 4" Lesson
>> Scott Moss: So we have a new objective. So if you look at this one, you go into server js, the file we've been working out of, first you'll notice there's two more files, there's a lions.js there's a tigers.js, all right, that's two more files. So at the TODO at the top it says, mount the tigers route with a new router, a a, just for tigers exactly like the lions is below.
[00:00:26] So if we go down here I have the app's middleware.
>> Scott Moss: And then I'm doing mounting right? I'm like okay, if anyone does a request, any verb to this route, use the lionrouter. So, where did the lionrouter come from? Well, let's follow it. Lionrouter right here, it's being required from the lions file, so let's go into the lions file, boom.
[00:00:49] First thing I did was, I made a lionrouter. This is all filled out for you, you will not be working in this file. I made a lionrouter, and then the rest of the stuff is the exact same stuff we had on the last example with the only change of getting rid of app and attaching auto functionality to the lion router itself.
[00:01:06] You see that? So I make a new router by using the .router method on express, and instead of using app.param and app.get, I'm using the router.param, router.get, router.post. And then at the very bottom, I need to export that router therefore I can require it in server js. So this is all filled out for you.
[00:01:30] So that's where that router came from, it was exported and then required. So what I want you to do is to go into Tigers.js, which has absolutely nothing in it but some comments and do the exact same thing as we did in Lions. It's the same thing, I mean you can just copy the same crud if you want to, but I want you to get the router to work.
[00:01:54] Lions and tigers are the same thing, they have the same resources, they do the same thing. The only difference is one's called lion and the other one's called tiger. I just want you to create a new router, add the crud to the router, you can literally copy this same crud and replace lion with the word tiger, and export that router, and then make sure we mount it over here.