node.js基础 1之简单的nodejs模块

    模块流程:

    创建模块-》导出模块-》加载模块-》使用模块

    ndoejs主要就是把项目变成模块化在管理

     实现一个模块的调用,编写student.js、teacher.js、klass.js、index.js(入口)

用exports导出模块exports.add=function()、require加载模块var teacher=require('./teacher.js')
使用模块teacher.add('Scott')
注意:exports、function等关键字不能写错(出错experts,funtion)


 最后在命令行中启动服务:

完整代码资料:https://github.com/juneldmm/nodejs/tree/master/school

原文地址:https://www.cnblogs.com/maggie-php/p/5914123.html