Node.js watchFile错误。 “未定义不是一个功能”

时间:2011-10-01 04:26:08

标签: javascript javascript-events node.js file-io

我是Node.js的新手,我正在尝试运行简单的Node.js代码。

我有Node.js windows 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)

任何想法????

1 个答案:

答案 0 :(得分:1)

Hej GG

Hej我非常支持在Windows上尚未支持watchFile

https://github.com/joyent/node/issues/1358

相关问题