node. js (window) Basics (2) modules in--node environment, inter-module calls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.