开发者

Node.js watchFile error. "Undefined is not a function"

开发者 https://www.devze.com 2023-04-10 12:04 出处:网络
I am new to Node.js and I am trying to run simple Node.js code. I have Node.js windows binary.v0.5.8 Here is my js code.

I am new to Node.js and I am trying to run simple Node.js code.

I have Node.js windows binary.v0.5.8

Here is my js code.

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);
});

When I keep only the readFile in the code it runs smoothly. But gives following error on 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 (mo开发者_StackOverflowdule.js:303:12)
    at Array.<anonymous> (module.js:463:10)
    at EventEmitter._tickCallback (node.js:200:26)

Any idea?


I am pretty sure that watchFile is not yet supported on windows:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消