in the in Nodejs, a module divides all functions into units and provides a complete module loading mechanism.
module in Nodejs is a very important concept that allows us to introduce third-party class libraries into our applications.
in the in Nodejs you can write or introduce several module files:
1) js script file with suffix . js.
2) A JSON text file with the suffix . json.
3) a compiled binary module file with the suffix. node.
There are two ways to access members within a module outside the module:
1. use The exports object to expose the object. For example:exports.msg=msg; the msg was exposed.
2 . Define the module as a class. For example:module.exports=foo;foo is the exposed class.
Require ("Index.js"); The file is loaded from the Node_modules directory by default .
Properties of the Module object:
Module.id: ID of the current module .
Module.filename: The file name of the current module file.
Module.loaded: boolean value. false indicates that the module is not loaded and True indicates that the module has finished loading.
Module.parent: The parent Module object of the current module.
Module.children: The property value is an array that holds all the submodule objects of the current module, that is, all the module objects that have been loaded in the module.
Note: Nodejs Official Package Warehouse website:http://registry.npmjs.org
This article is from "Time" blog, please make sure to keep this source http://timeblog.blog.51cto.com/8650972/1588755
node. JS module and NPM Package management tool