1. What is Modular
File scope
Communication rules
Load require
Export exports
2, COMMONJS module specification
JavaScript in node also has a very important concept: module concept
Module scope
Use the Require method to load a module
Syntax: var custom variable name = require (' module ')
Two functions:
Executing the code in the loaded module
Get the exports export interface object in the loaded module
Use the exports excuse object to export members in a module
The module scope in node, in which all members of the default file are valid in the current file module
For members who wish to be accessed by other modules, we need to attach these exposed members to the object of the exports interface.
Exporting multiple members must be in the object
Module.exports = {
Key: Value,
..........
} or module.exports.xxx = xxx;
Export a single member must be module.exports.xxx = XXX;
Note: Module.exports = = = Exports
(Supplementary one humorous: 301 Status Code Permanent orientation, browser will remember, 302 status code temporary redirect)
COMMONJS Module Specification