Node.js模块系统
时间:2019-03-12 13:16:02
收藏:0
阅读:147
目的:可以使node的文件相互调用
Node.js 提供了 exports 和 require 两个对象,
exports 是模块公开的接口,
require 用于从外部获取一个模块的接口,即所获取模块的 exports 对象。
格式如下:
module.exports = function() {
// ...
}
exports 和 module.exports 的使用
暴露属性或方法,就用 exports 就行,
要暴露对象(类似class,包含了很多属性和方法),就用 module.exports。
原文:https://www.cnblogs.com/joer717/p/10515762.html
评论(0)