首页 > Web开发 > 详细

Nodejs_day01

时间:2015-09-14 21:05:41      阅读:245      评论:0      收藏:0      [点我收藏+]

helloworld.txt的内容:

我是nodejs

 

阻塞式调用

var fs = require(‘fs‘);

var data = fs.readFileSync(‘helloworld.txt‘);

console.log(data.toString());

console.log("程序执行完毕!");

执行结果:

我是nodejs

程序执行完毕!

 

非阻塞式调用:

var fs = require(‘fs‘);

fs.readFile(‘helloworld.txt‘,function(err,data){

  if(err){return console.error(err);}

  console.log(data.toString());

});

console.log("程序执行完毕!");

执行结果:

程序执行完毕!

我是nodejs

 

Nodejs_day01

原文:http://www.cnblogs.com/liyajie/p/4808144.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!