node.js模块

nodejs每个模块都是独立的作用域

模块流程图:

  • 创建模块 teacher.js 入口的js文件
  • 导出模块
    exports.add=function(){}
    此处exports是对象可以接任意方法属性exports.add=add等价于module.exports.add
  • 加载模块
    var teacher=require('./teacher.js')
  • 使用模块
    teacher.add('Scott')
You can change the world with your heart,even a lot of changes sometimes unless you won't geiv up....
原文地址:https://www.cnblogs.com/xiongwei2017/p/6583788.html