dongnuo4594 2016-09-12 10:11
浏览 82


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.

  • 写回答

2条回答 默认 最新


      相关推荐 更多相似问题


      • ¥20 有ASP .NET MVC做的小说阅读网站吗?
      • ¥20 beeline客户端支持ipv6地址连接hive服务
      • ¥15 香农解码的代码问题,无法输出解码结果
      • ¥15 Python操作注册表
      • ¥45 入门级别的一段VUE前端拍照像后端发送请求的代码,帮排错
      • ¥15 anaconda打开spyder后一直闪退,不知道怎么办
      • ¥15 解决迷宫问题中无法运行的问题
      • ¥15 关于aspnetcore中使用mqttnet库的entire
      • ¥15 关于#python#的问题,请各位专家解答!
      • ¥100 关于远控软件的两个问题