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. 十天冲刺---Day9

    站立式会议 站立式会议内容总结: 燃尽图 照片 队员们都回来了,写完之后继续对alpha版本进行迭代. 希望演示的时候能拿得出来.

  2. 深入 理解vxlan

    VXLAN RFC 文档 : https://tools.ietf.org/html/rfc7348 作为网络虚拟化的重要技术,VXLAN备受关注,该协议是如何运作的?如何通过数据与控制层面的分离实现 ...

  3. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

  4. Asp.Net MVC<一> : 三层架构、MVC

    MVC.MVP.MVVM.Angular.js.Knockout.js.Backbone.js.React.js.Ember.js.Avalon.js.Vue.js 概念摘录 认清Android框架 ...

  5. Js 校验时间、比较时间 和转换时间格式

    function checkDate(obj){ var strDate = obj.value; var nowDate = new Date(); var a=/^(\d{1,4})(-|\/)( ...

  6. window 系统设置无线wifi

    netsh wlan set hostednetwork mode=allow ssid=huage key=243573295 如上表示设置成功 然后继续输入 netsh wlan start ho ...

  7. spring spel

    •Spring 表达式语言(简称SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言.   •语法类似于 EL:SpEL 使用 #{…} 作为定界符,所有在大框号中的字符都将被认为是 SpE ...

  8. JAVA gc垃圾回收机制

    一.GC概要   JVM堆相关知识     为什么先说JVM堆?     JVM的堆是Java对象的活动空间,程序中的类的对象从中分配空间,其存储着正在运行着的应用程序用到的所有对象.这些对象的建立方 ...

  9. 【2016 ACM/ICPC Asia Regional Qingdao Online】

    [ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...

  10. github图片

    github:https://github.com/BigShow1949/BigShow1949