node 模块正确暴露方法

一个node模块,为了能够服用,就需要将其暴露,那么如何正确写呢?(参考:https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/Introduction

【正确写法A】

exports.area = width => { return width * width; };
exports.perimeter = width => { return 4 * width; };

【正确写法B】

module.exports.area = width => { return width * width; };
module.exports.perimeter = width => { return 4 * width; };

【正确写法C】

// 这种写法只能用 module.exports
module.exports = {
  area: width => { return width * width; },
  perimeter: width => { return 4 * width; }
};
原文地址:https://www.cnblogs.com/lishidefengchen/p/12055805.html