This course has been updated! We now recommend you take the Introduction to Node.js, v3 course.
Transcript from the "Modules Recap" Lesson
>> Scott Moss: So we talked about three different modules already, right? We talked about modules that you create, modules that are internal the shipped modules, and the remote modules. So because it's three different module types, but there's only one require statement, you know, we will talk about how the different ways to require them.
[00:00:16] So I'll talk a little bit about it, but basically custom local modules are like this right you always have with a DOT. And then follow by the relative path, that's it for custom modules. And custom modules are modules that you created locally. For remote modules, you just put the name of the module.
[00:00:34] How do you know the name of the module? I'm gonna show you what that is. But most of the time, it's the same name as the repo, it's the same name of whatever it is on npm. And I'll show you how to actually find the real name of it.
[00:00:45] That part's not hard. It's harder than it sounds, but it's not hard to figure that out. But yeah, you just put the name, no dot. It's just like you do an internal module, you just put the name of it. And again, the same thing for internal shipped modules, it's just a name.
[00:00:55] You just put the name of it. That's it.
>> Scott Moss: That's all you gotta do. The only difference here is that if there's a remote module that you downloaded, that you installed, and it has the same name as an internal module. The remote module will win. So the remote module called FS and you require FS then npm or node is gonna get the one from the remote module that you install, not the internal one.
[00:01:21] So yeah if some jerk made a module with the same name as an internal node module, don't use it. And that person was like wrong for doing that. That was a really bad move. They should not have done that because they knew what they were doing. People usually do that, they usually get hacky about that.
[00:01:34] They will be like I'm going to name it path, like the same name as a module that node has. So everybody has to use it and then they will install it. And then the next thing you know is you are using some malicious code and you don't even know.
[00:01:45] So like, yeah, if there's a package with the same name as an internal module, it's probably bad. I just would not use it. So just don't do it.