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