dongnuo4594 2016-09-12 10:11
浏览 82
已采纳

使用Node.js在WAMP服务器中查看文件

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条回答 默认 最新

  • dongxuxian1123 2016-09-12 10:46
    关注

    I have found the solution. With that simple code and don't need to install any library in WAMP Server.

    Solution: Is it possible to retrieve the last modified date of a file using Javascript?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数
  • ¥15 ADS时域 连续相位观察方法
  • ¥15 Opencv配置出错
  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused