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的更多相关文章

随机推荐

  1. Spring AOP基础知识

    Spring AOP使用动态代理技术在运行期织入增强的代码,两种代理机制包括:一是基于JDK的动态代理,另一种是基于CGLib的动态代理.之所以需要两种代理机制,很大程度上是因为JDK本身只提供接口的 ...

  2. openfire插件开发1

    http://www.cnblogs.com/hoojo/archive/2013/03/29/openfire_plugin_chatlogs_plugin_.html http://www.cnb ...

  3. c# 计算1-100之间的所有奇数的和

    求1-100之间所有奇数整数和: class Program { static void Main(string[] args) { ,); Console.WriteLine("1-100 ...

  4. 最短JS判断是否为IE6(IE的写法) (转)

    常用的 JavaScript 检测浏览器为 IE 是哪个版本的代码,包括是否是最人极端厌恶的 ie6 识别与检测. 代码如下: var isIE = !!window.ActiveXObject; v ...

  5. Android: 启动init.rc 中service的权限问题【转】

    转自:http://www.linuxidc.com/Linux/2011-04/35014.htm 通过property_set("ctl.start", service_xx) ...

  6. Oracle HRMS API – Create Employee

    -- Create Employee -- ------------------------- DECLARE   lc_employee_number            PER_ALL_PEOP ...

  7. [LintCode]perfect-squares(DP)

    题目链接:http://www.lintcode.com/zh-cn/problem/perfect-squares/ 就是求最小价值的完全背包,初始化dp[i]=i,假设全是1的时候是最多的,之后就 ...

  8. android 启动第三方程序的代码

      //启动媒体库 Intent i = new Intent(); ComponentName comp = new ComponentName("com.android.camera&q ...

  9. aptana studio 3支持jquery

    首先要说的一点是,如果你不使用PortableGit,就不要安装,否则New From Template中会缺失大部分模板.至于还有什么缺陷,暂时没测出来,本人也是刚玩aptana studio 3哈 ...

  10. Qt之显示网络图片

    简述 Qt中包含了网络模块-network,我们可以很容易的进行各种网络编程和数据传输,关于network的类很多,其中包含:支持DNS.HTTP.TCP/UDP等众多高级类,可以参考助手. 下面我们 ...