首页 > 编程 > JavaScript > 正文

nodeJS模块简单用法示例

2019-11-19 13:59:00
字体:
来源:转载
供稿:网友

本文实例讲述了nodeJS模块简单用法。分享给大家供大家参考,具体如下:

1.定义Student模块,Teacher模块

function add(student){  console.log('Add Student:'+student);}exports.add=add;function add(teacher){  console.log('Add Teacher:'+teacher);}exports.add=add;

2.定义kclass模块

//引入student模块var student=require('./student');//引入teacher模块var teacher=require('./teacher.js');function add(teacherName,students){ teacher.add(teacherName); students.forEach(function(item,index){  student.add(item); });}//向模块对象,注册方法exports.add=add;

3.定义启动模块 index.js

var class1=require('./kclass.js');class1.add('高一班',['张三','李四']);

运行结果:

希望本文所述对大家nodejs程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表