1. Introduction of the module:
In a node. JS module system, each file is treated as a standalone module.
2. Module classification:
(1) built-in modules
(2) third-party modules
(3) Custom modules
3. Module use:
(1) Export
(2.1) Module.exports = {}
(2.2) module.exports.xxx = {}
(2.3) exports.xxx = {}
(2) import require ()
Rrequire () can omit the extension when loading the file, it will first load the JS file, if there is no JS file to load the JSON file, and no JSON file to load. node file, so always follow this priority selection, but each require () will only load a file;
4. Module path:
(1) __filename the file name of the current module---the absolute path after parsing.
Console.log (__filename); // C:\Users\xdl\Desktop\test\fs.js
(2) __dirname to get the directory name of the current module.
Console.log (__dirname); // C:\Users\xdl\Desktop\test
Nodejs-4.module Modular