This course has been updated! We now recommend you take the Introduction to Node.js, v2 course.
Transcript from the "Other Internal Node Modules" Lesson
>> Scott Moss: Cool, so let's get back to this. So that's one process, very helpful, cannot live without it. Http, you will almost never use this directly, except for today, cuz you will use this today. Other than that, you will almost never use this module directly because it's just, I hate saying the word, low-level, because compared to other languages and implementations, it's not low-level, but compared to Node and what it does, it is very low-level.
[00:00:26] But basically, its job is to, it's a module for creating network-based programs like APIs. So if you want a server or something that's network-based, you would use the http module. But again, you will almost never use it directly. You will use some other module that uses this cuz it's very hard to manage, very, very difficult to build stuff.
[00:00:45] Too many edge case, you got a little bit a lot of networking and understand math and stuff like that. But yeah, you will use something that uses this versus using it. But every single package that does any type of networking in Node uses http. Path is a very useful one, you also use it a lot.
[00:01:07] OS X, Windows, they treat paths completely different. Even the way that the slashes are backward, so everything is completely different. So if you were trying to find a relative path to a file that you were trying to read, and you passed it in thinking, cuz you're on a MacBook, it wouldn't work on Windows.
[00:01:21] So how do you get around that? Well, path kinda normalizes everything for you. It concatenates paths for you, gets rid of trailing edges, trailing slashes, all that stuff, kinda fixes it all for you. It'll even resolve, it'll walk the tree and find paths for you if you just don't know.
[00:01:37] It might be there, maybe it's not there. So that's what the path module is for. Also very helpful, it works hand in hand with the fs module. I highly recommend using them together. In fact, you will be doing it on your exercises today. So yeah, path, if you ever gonna do anything, where you're like, yeah, I need something like this.
[00:01:56] If you're doing that anywhere other than the require statement, you need to use the path module. Just use it because it's gonna eliminate so many problems for you. So the only time I would ever recommend is hard-coding a path like this is in the require statement, because it internally uses the path.
[00:02:11] Every other thing, use path. Just path.join, which again, to require an internal module, you just say the name of it and this ones called path. So path.join which is really helpful, so if I was like, I wanna join('../../hello', 'app/', '../things'), right? This thing will give me a proper path that works.
[00:02:46] Let me get rid of this. See, it kind of normalize a path for me, so I don't have to think about it. Whereas, if you try to do all that yourself, it would just not make sense. You would like, gotta get rid of this dot and add this slash, path does it for you.
[00:03:00] So highly recommend using that. There are a lot more. URL is one, it's really helpful. You'll see that in some of the exercises. Crypto is pretty good if you're doing some crypto stuff, and I'm not talking about cryptocurrencies. I'm talking about security stuff. And what's some other useful ones?
[00:03:22] Those are mostly it. Everything else, you're pretty much gonna download from the Internet, or make yourself. Seriously, that is literally it. But fs is godsend, it's amazing. Okay, and again, these come shipped with Node, and depending on what version of Node, that's gonna determine how these modules work.
[00:03:38] You gotta go look at the documentation to see like, fs has this method in this version, but in this version, it doesn't. So these packages change depending on what version of Node you're using, they do different things. And I would say, everything, Node 6 and beyond is just huge change.
[00:03:53] Everything before Node 6 is just like, yeah, I wouldn't trust it. Just don't use it. Node 6 and beyond is amazing, and it's pretty much standard going forward, but yeah.