node.js学习笔记之写文件

node.js之写文件

//---------------optfile.js------------------
var  fs=  require('fs');
module.exports={
    writefile:function(path,data){    //异步方式
        fs.writeFile(path,  data,  function  (err)  {
            if  (err)  {
                throw  err;
            }
            console.log('It\'s  saved!');  //文件被保存
          });
    },
    writeFileSync:function(path,data){  //同步方式
        fs.writeFileSync(path,  data);
        console.log("同步写文件完成");
    }

}

教程学习地址: http://study.163.com/course/introduction/1003228034.htm#/courseDetail

posted @ 2016-12-17 21:56  老何de技术日志  阅读(498)  评论(0编辑  收藏  举报