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