【发布时间】:2017-01-19 18:05:47
【问题描述】:
我需要在 WAMP 服务器中监视一个文件,以便当文件更改时 javascript 可以运行一个函数。
我进行了一些搜索并看到了 Node.js 库,但在 wamp 服务器中使用时遇到了问题。我运行了 Node.js 的设置以安装在我的计算机中。但是当我在我的网页中调用它时:
var fs = require('fs');
console.log('Watching watcher.txt');
fs.watchFile('watcher.txt', function(curr,prev) {
console.log('current mtime: ' +curr.mtime);
console.log('previous mtime: '+prev.mtime);
if (curr.mtime == prev.mtime) {
console.log('mtime equal');
} else {
console.log('mtime not equal');
}
});
我得到这个错误:“Uncaught ReferenceError: require is not defined”。
有人可以帮助我吗? Wamp Server 中的 Node.js 让我很困惑。
【问题讨论】:
标签: javascript php node.js wamp wampserver