Node.js模块系统

目的:可以使node的文件相互调用

Node.js 提供了 exports 和 require 两个对象

 exports 是模块公开的接口,

require 用于从外部获取一个模块的接口,即所获取模块的 exports 对象。

格式如下:

Node.js模块系统
module.exports = function() { // ... }

exports 和 module.exports 的使用

暴露属性或方法,就用 exports 就行,

要暴露对象(类似class,包含了很多属性和方法),就用 module.exports