I need to watch a file in WAMP Server, so that when the file changes the javascript can run a function.
I have done some search and saw the library Node.js, but I am having a problem to use in wamp server. I ran the setup of Node.js to install in my computer. But when I call this in my webpage:
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');
}
});
I get this error: "Uncaught ReferenceError: require is not defined".
Can someone help me? The Node.js in Wamp Server is doing a lot of confusion in my head.