2011-10-01 99 views
0

我是新来的Node.js,我试图运行简单的Node.js代码。Node.js watchFile错误。 “未定义不是函数”

我Node.js的窗户binary.v0.5.8

这里是我的js代码。

var fs = require("fs"); 

fs.readFile('message.text', 'utf8', function (err,data) { 
    if (err) { 
    return console.log(err); 
    } 
    console.log(data); 
}); 

fs.watchFile('message.text',function (curr, prev) { 
    console.log('the current mtime is: ' + curr.mtime); 
    console.log('the previous mtime was: ' + prev.mtime); 
}); 

当我在代码中只保留readFile时,它会平稳运行。 但在watchfile上给出以下错误。

C:\Users\GG\Labs\NodeJS>node.exe test.js 

node.js:208 
     throw e; // process.nextTick error, or 'error' event on first tick 
      ^
TypeError: undefined is not a function 
    at new StatWatcher (fs.js:596:18) 
    at Object.watchFile (fs.js:648:37) 
    at Object.<anonymous> (C:\Users\GG\Labs\NodeJS\test.js:25:4) 
    at Module._compile (module.js:425:26) 
    at Object..js (module.js:443:10) 
    at Module.load (module.js:344:31) 
    at Function._load (module.js:303:12) 
    at Array.<anonymous> (module.js:463:10) 
    at EventEmitter._tickCallback (node.js:200:26) 

任何想法????

回答