Node.js watchFile 错误。 “未定义不是函数”
我是 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)
有什么想法吗?
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 (module.js:303:12)
at Array.<anonymous> (module.js:463:10)
at EventEmitter._tickCallback (node.js:200:26)
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定 Windows 尚不支持
watchFile
:https: //github.com/joyent/node/issues/1358
I am pretty sure that
watchFile
is not yet supported on windows:https://github.com/joyent/node/issues/1358