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; }
};

 

posted @ 2019-12-17 17:41  lishidefengchen  阅读(1569)  评论(0编辑  收藏  举报