nodejs模块
nodejs模塊遵循commonJS規范,但并不是完全實現規范,主要使用require引入模塊、使用exports導出模塊。
導出屬性或方法
使用exports
mouduleA.js:
index.js中引入:
var mA = require('./moduleA')mA.saySomeThing('hello') mA.singSomeThing('world')導出對象
使用module.export
moduleB.js:
index.js中引入:
var mb = require('./moduleB') var thatway = new mb() thatway.setName('thatway') thatway.sayHello()總結
- 上一篇: webstorm中nodejs代码提示
- 下一篇: nodejs常用模块-url