Nodejs's Simple Nodejs module

Source: Internet
Author: User

For example: Schools have students, teachers, and classes, each of which is a module

Create a school local file, new student.js teacher.js klass.js//Because class is a keyword

Then implement the contents of each module:

Student.js

function Add (student) {  console.log (' Add student: ' + student)}//Mount Exports.add = add

Teacher.js

function Add (Teacher) {  console.log (' Add Teacher: ' + teacher)}//mount Exports.add = Add  //Mount

Klass.js

Student teacher require to Klass

var student = require ('./student ') var teacher = require ('./teacher ') function Add (teachername,students) {Teacher.add ( TeacherName) Students.foreach (function (item,index) {Student.add (item);})} Exports.add=add

Create a master page index.js

var Klass = require ('./klass ') klass.add (' Zhangsan ', [' Lisi ', ' Wangwu ', ' Zhaoliu '])

CMD Open Command window to enter school file or SHIFT + right mouse button here to open command window

Enter the command node index results as shown below

Nodejs's Simple Nodejs module

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.