日期:2014-05-16 浏览次数:20307 次
var fs= require('fs'); //异步读取文件 fs.readFile('app.js','utf-8',function(err,data){ if(err){ console.error(err); }else{ console.log(data); } }); console.log("Ending ..");
var fs= require('fs'); //同步读取文件 data = fs.readFileSync('app.js','utf-8'); console.log(data); console.log("Ending ..");
var EventEmitter = require('events').EventEmitter; var event = new EventEmitter(); //注册some event 事件 event.on('some_event',function(){ console.log('some event occured.'); }); setTimeout(function(){ //发送一个some_event 事件 event.emit('some_event'); },1000);