Nodejs require11/1/2022 Thus, you successfully added the two properties in the module.exports object so that the functions - calculateArea and calculateCircumference can be exported from the circle module to some other module. The constructs - calculateArea and calculateCircumference, added to the module.exports, object are logged. The default value of module.exports object is exports is a key of the module object, the corresponding value of which is an object. The module parameter (rather a keyword in a module in Node) refers to the object representing the current module. Let’s discuss these two parameters in this article. So, the question that arises now is how do you specify something in a module that can be used by some other module? This is when the module & require parameters of the function wrapper are helpful. It means that you cannot use these constructs in any other module unless explicitly specified. An important point to keep in mind is that all these constructs are private to the circle module by default. There are three constructs defined in this module - a constant variable PI, a function named calculateArea and another function named calculateCircumference. Let’s revisit the circle module, which you looked at earlier. These parameters provide valuable information related to a module. Nodejs require code#Though these parameters are global to the code within a module yet they are local to the module (because of the function wrapper as explained above). The five parameters - exports, require, module, _filename, _dirname are available inside each module in Node. (Remember each function in JavaScript has its own local scope?) This is the reason why module A cannot access the code written inside module B and vice-versa. Because the code pertaining to both the modules is enclosed within different functions, these functions will not be able to access the code of each other. Similar thing happens with the code written inside the module B. The code written inside the module A is enclosed within the function wrapper corresponding to the module A. Imagine that there are two modules - A and B. Code written inside a module is private to it!
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |