Reference: Http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/ 001434502419592fd80bbb0613a42118ccab9435af408fd000
1, Node Environment module concept: A name.js file is a module, name is the module name, the function method in the module is called a variable.
2. Call of module variable: output variable in a.jsmodule.exports=函数名称; B.js引入模块var name=require(‘./moduleName‘);
Note: when you introduce a module, the path uses a relative path
3. The output variable collection is not the same as a single Variable object call methodEg:
A.js (output variable js)
1 vars= ' Hello ';2 functionGreet (name) {3Console.log (s+ ', ' +name+ '! '));4 }5 functionsum (x, y) {6 returnx+y;7 }8 /*exposing a single output variable is not the same as calling methods that expose a variable array*/9 Ten //exposing the function as the output of the module One //Module.exports=greet; A - //Exposure module multiple variable outputs -module.exports={ the Greet:greet, - Sum:sum -};
B.js (call JS)
1 varFuna=require ('. a '));2 vars= ' Sun ';3 /*calling a single output variable is not the same as the method of a variable array*/4 5 //invoking a single output variable6 //Funa (s);7 8 //call an array of output variables9 Funa.greet (s);TenConsole.log (Funa.sum (10,20));
I am node. js on the way to study, if there is anything wrong also ask you to correct.
node. js (window) Basics (2) modules in--node environment, inter-module calls