node.js

来源:互联网 发布:软件测试工作分类 编辑:程序博客网 时间:2024/05/17 04:16

node.js提供了两个对象exports和require,其中 exports 是模块公开的接口,require 用于从外部获取一个模块的接口,即所获取模块的 exports 对象。

比如希望main.js可以引用hello.js对象的成员函数,用exports把hello.js中的对象作为模块的访问接口,然后在main.js中用require(./hello)加载这个模块,就可以用hello.js中exports的对象函数了。

格式:module.exports=function(){

           ......

}


require方法接受以下几种参数的传递:

  • http、fs、path等,原生模块。
  • ./mod或../mod,相对路径的文件模块。
  • /pathtomodule/mod,绝对路径的文件模块。
  • mod,非原生模块的文件模块。


fs.readFile()异步

fs.readFileSyco()同步


0 0
原创粉丝点击