Loading...
「ツール」は右上に移動しました。
利用したサーバー: natural-voltaic-titanium
2いいね 42回再生

The Anatomy of a Node.js Module Part 7

The anatomy of a Node.js module. The Node.js module is just any JavaScript file in the node environment. So all the dodgy extensions are considered modules, it contains reusable code, some code that can be shared by other modules. And so in order for them to be shareable, you need to export them, and also important to the other modules. So let's take a look at an example here. Let's say that we have a module called user.js. Inside this module these are some typical things you usually see. So first we usually import other modules into this module so you can use them. So these modules can be your own local modules. Some can be a third party, some of the core modules provided by note. And in this module you could have things like a class, and a function or a lot of functions, in order for these classes functions to be exposed able to other modules, you have to export them out. And we export them export through the module that exports object and attach that to the exports property. And then those can be accessed in other modules. So let's see how modules work and the Node.js Project. So let's say you have a module A, this module A can be used or importing or exporting and importing two other modules like B C and D E here. And in turn these modules, for example, B and D can be exported into other modules have G and H. And then of course like module age can also receive another module from a module I as well. So you can see that like a module age contains the import of module A D and I right. So this is how modules work and in Node.js application. A node, there are three major types of modules. So from the very bottom of the core of this environment are the core modules. These are the modules that come by default when you install node, things like the http module, fs power system, query and string and so forth. And on top of these are the massive, massive third party modules. These are the modules that are uploaded to the NPM registry that you can download for free. Again, they're about probably 800,000 probably close to a million now I guess of all these modules you can download use for free and new application, without having to having to reinvent the wheel. It's pretty cool, right. And then on top of these are your local modules. These are the modules that you create your own, and you write them yourself. And so when you create a module a project, when you're done with your module and you if you want to share with the world, add to the third party you put into a package and you upload to the registry. So that's how modules work in Node.js environment. Now that we know what modules are and how they are structured in the next video, we'll learn to create our own modules, and how to use them to execute these modules in a new application.

コメント