This course has been updated! We now recommend you take the API Design in Node.js, v4 course.
Transcript from the "Audience Q&A" Lesson
>> Speaker 1: You can use web star for IntelliJ for debugging.
>> Speaker 2: Webstar or IntelliJ for debugging. I wouldn't know that because I don't use those, but that's might be the reason why I should use them. So that sounds awesome.
>> Speaker 1: Yeah, those are the best tools outside of inspector.
>> Speaker 2: Nice, I did not know that. Great. I'm probably gonna check it out tonight then [LAUGH]. Yes?
>> Speaker 1: So in a real example, the reason behind using routing is to reuse some of the code, or what's the main reason behind routing?
>> Speaker 2: Are you saying the reason behind making these subrouters?
>> Speaker 1: Yeah.
>> Speaker 2: Right. So it's just too abstract a piece of functionality, right? So now we get to abstract different resources completely away. And they have their own configuration. So that's the sweet thing. It's like they share some global configuration, as in server JS. They share disk configuration.
[00:00:56] But they also have their own configuration that's specific and unique to them, right? And we're not polluting other resources with that configuration. So just the fact that it's abstracted out, which is really great. Which, I think, just leads to all types of benefits as much as like working with different people in the same project.
[00:01:13] Now you can work on different things completely separate and not have to worry about waiting on this person, right? And also, maybe you're doing very unique things with this one thing. Maybe for lion.js you're writing it in ES6 and it's using a different version of Express. Or maybe it's using a different version of a database, or something like that.
[00:01:34] It's doing something different, so you need it to be completely isolated, then register it later. So, things like that. It's just like having a application in an application, is just many benefits.
>> Speaker 2: Yeah?
>> Speaker 2: Any other questions? Mark?
>> Speaker 1: I think Tom was just saying he'd mentioned the response on finish for middleware.
>> Speaker 2: The response on finish.
>> Speaker 2: I'm not sure what he's referring to-
>> Speaker 1: Or maybe I thought he meant for you to bring that up, but I'll check with what he's saying. And then somebody else was asking, where's this morgan thing being used?
>> Speaker 2: Yeah, morgan. Server.js. Right here.
[00:02:12] So, if you'll look, I'll just show you. If I run the server.
>> Speaker 2: Oops, it's already running. It's over here.
>> Speaker 2: There we go. So the server's running. Let me clear the output. There's no output right now, right? There's nothing here, I just cleared it. But the server's still on, and if I go to the app, I refresh, and I look at the output.
[00:02:40] All this stuff that's being logged in the terminal, that's morgan doing that, morgan is logging this. If we get rid of morgan, we won't see anything. Yes?
>> Speaker 1: Is there anything that will log the request as well as the body of a host or a put?
>> Speaker 2: Log the-
>> Speaker 1: That tells me the call was made, but not actually what got pushed across.
>> Speaker 2: So, there are different levels to morgan. If you got rid of dev, we can see what happens. So, let me see. I got rid of dev, says it deprecated. Looks like you gotta do something.
[00:03:10] I don't know. So, but yeah, if morgan doesn't do, then, yeah, you can make your own, right? So you could just, what you could do is you come in here, actually, let's just do it right now. We'd have to make sure we're after the body parts here. So JSON's there.
[00:03:22] We'll make a new request right here, right? And we'll make a new middlewear, and we'll get the request.
>> Speaker 2: And a response. And next. And you said you want to log the request and the response?
>> Speaker 1: Well, the body of what's coming in.
>> Speaker 2: Okay, the body. So, we'll say console.log, the body.
[00:03:44] And then we could just say req.body, and then we can say next.
>> Speaker 2: There we go. So now when we
>> Speaker 2: do something, there it is. The body. So if I post something
>> Speaker 2: The body. All right? There you go, yeah. So super easy to make yourself with middleware.
[00:04:14] Any other questions? Yes.
>> Speaker 1: Somebody had posted a while ago a snippet of the middleware that console logs how long each request is taking. But morgan's doing that for us, right?
>> Speaker 2: Yeah. Morgan actually tells you how long is taking [CROSSTALK]
>> Speaker 1: Yeah. It will tell you how long it took.
>> Speaker 2: Okay. They're asking what theme you're using in sublime text.
>> Speaker 1: Yeah. So, theme is seti, S,E,T,I. And color scheme is, let me see. All right. Let me see, it's-
>> Speaker 2: We should just have every teacher that teaches-
>> Speaker 1: Their stack.
>> Speaker 2: Their list of like theme and config and all that stuff.
[00:05:00] Cuz it's like, if someone's using vim it's like what extensions are you using?
>> Speaker 1: [LAUGH]
>> Speaker 2: What plugins are you using?
>> Speaker 1: Yeah, so the theme is SETI. And the actual color and syntax is Brogrammer. So you're an official brogrammer?
>> Speaker 2: I just downloaded it yesterday cuz it looked cool.
[00:05:20] But another one that I like is glaciers, the one I had before this. It was really good. All right. It's not on here now. But, yeah, that's what I have. Brogrammer, yeah.