fs.watchFile(filename[, options], listener)#
Added in: v0.1.31
filename <String> | <Buffer>
options <Object>
persistent <Boolean>
interval <Integer>
listener <Function>
Watch for changes on filename. The callback listener will be called each time the file is accessed. The options argument may be omitted. If provided, it should be an object. The options object may contain a boolean named persistent that indicates whether the process should continue to run as long as files are being watched. The options object may specify an interval property indicating how often the target should be polled in milliseconds. The default is { persistent: true, interval: 5007 }. The listener gets two arguments the current stat object and the previous stat object: fs.watchFile('message.text', (curr, prev) => {
console.log(`the current mtime is: ${curr.mtime}`);
console.log(`the previous mtime was: ${prev.mtime}`);
});
These stat objects are instances of fs.Stat. If you want to be notified when the file was modified, not just accessed, you need to compare curr.mtime and prev.mtime. Note: when an fs.watchFile operation results in an ENOENT error, it will invoke the listener once, with all the fields zeroed (or, for dates, the Unix Epoch). In Windows, blksize and blocks fields will be undefined, instead of zero. If the file is created later on, the listener will be called again, with the latest stat objects. This is a change in functionality since v0.10. Note: fs.watch() is more efficient than fs.watchFile and fs.unwatchFile. fs.watch should be used instead of fs.watchFile and fs.unwatchFile when possible.

nodejs fs module的更多相关文章

  1. nodejs fs path

    内容详见我的gitHub: https://github.com/shangyueyue/ssy-utils/tree/master/src/nodejs/fs

  2. NodeJs 的Module.export 和 export

    NodeJs  的Module.export 和 export 是一样的. 但是Module.export ={....} 可以起效,.export ={....} 是失效的. 这里的export  ...

  3. nodejs 中module.exports 和 exports 区别详细介绍

    你肯定非常熟悉nodejs模块中的exports对象,你可以用它创建你的模块接下来介绍创建过程,感兴趣的朋友可以参考下 你肯定非常熟悉nodejs模块中的exports对象,你可以用它创建你的模块.例 ...

  4. NodeJs:module.filename、__filename、__dirname、process.cwd()和require.main.filename

    转载于: http://blog.csdn.net/bugknightyyp/article/details/17999473 module.filename:开发期间,该行代码所在的文件. __fi ...

  5. nodejs -- fs模块 ---> readFile 函数 1) fs.readFile(filename, "binary", function(error, file) 2) response.write(file, "binary");

    一:代码: 1.1 入口文件: index.js var server = require('./server'); var router = require("./router" ...

  6. ES6的export与Nodejs的module.exports

    原文:https://www.cnblogs.com/lxg0/p/7774094.html module.exports与exports,export与export default之间的关系和区别 ...

  7. 理解nodejs的module模块儿

    module 在 Node.js 模块系统中,每个文件都视为独立的模块,node在运行某个模块儿时会生成一个module对象 Module { id: '.', exports: 2, parent: ...

  8. NodeJS旅程 : module 不可忽略的重点

    modules 模块的简介 Module 是Node.js中最重要的一个部分也是进行深度开发前的必修课.掌握Module才能真正理解NodeJS的精髓,你会发现从思路上会有极大的扩展.  学会写mod ...

  9. NodeJs FS 文件系统模块

    1. fs.stat 检测是文件还是目录 fs.stat('html',function(err,stats){ if(err){ console.log(err); return false; } ...

随机推荐

  1. 东大OJ-最大子序列问题的变形

    1302: 最大子序列 时间限制: 1 Sec  内存限制: 128 MB 提交: 224  解决: 54 [提交][状态][讨论版] 题目描述 给定一个N个整数组成的序列,整数有正有负,找出两段不重 ...

  2. Bete冲刺第四阶段

    Bete冲刺第四阶段 今日工作: web: 昨晚搞得很晚,帮队友搞定了git的问题,仓库顿时干净多了,同时已经基本完成了基础功能的接口 ios: 导入并使用了改善交互的第三方开源库,修正路径BUG 目 ...

  3. jQuery鼠标悬停内容动画切换效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. centos中crontab(计时器)用法详解

    关于crontab: crontab命令常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行.该 ...

  5. 【CodeVS 2822】爱在心中

    “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our Home.” 在爱的国度里有N个人,在他们的心中都有着一个 ...

  6. 浅谈我对JCS 的理解

    JCS 是Java 中缓存的一种实现,支持将数据缓存到内存和硬盘中,支持设置缓存对象的有效时长. 我认为可以这么理解JCS:客户端向服务器发出请求,服务器就先去缓存中查一下有没有客户端请求的数据,有则 ...

  7. java中会存在内存泄漏吗,请简单描述。

    内存泄露就是指一个不再被程序使用的对象或变量一直被占据在内存中.Java 使用有向图的方式进行垃圾回收管理,可以消除引用循环的问题,例如有两个对象,相互引用,只要它们和根进程不可达的,那么GC也是可以 ...

  8. Linux的vim三种模式及命令

    一般模式:在Linux终端中输入"vim 文件名"就进入了一般模式,但不能输入文字.编辑模式:在一般模式下按i就会进入编辑模式,此时就可以写程式,按Esc可回到一般模式. 命令模式 ...

  9. [vijos1907][NOIP2014]飞扬的小鸟

    Description 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了水管或者掉在地上的话,便宣告失败. ...

  10. javaBean和Servlet有什么区别

    1.javabean无非就是里面有些set和get方法 2.servlet用来处理一些逻辑层 3.javabean.servlet.jsp分别对应M(odel).C(ontroller).V(iew) ...