nodejs fs module
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的更多相关文章
- nodejs fs path
内容详见我的gitHub: https://github.com/shangyueyue/ssy-utils/tree/master/src/nodejs/fs
- NodeJs 的Module.export 和 export
NodeJs 的Module.export 和 export 是一样的. 但是Module.export ={....} 可以起效,.export ={....} 是失效的. 这里的export ...
- nodejs 中module.exports 和 exports 区别详细介绍
你肯定非常熟悉nodejs模块中的exports对象,你可以用它创建你的模块接下来介绍创建过程,感兴趣的朋友可以参考下 你肯定非常熟悉nodejs模块中的exports对象,你可以用它创建你的模块.例 ...
- NodeJs:module.filename、__filename、__dirname、process.cwd()和require.main.filename
转载于: http://blog.csdn.net/bugknightyyp/article/details/17999473 module.filename:开发期间,该行代码所在的文件. __fi ...
- 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" ...
- ES6的export与Nodejs的module.exports
原文:https://www.cnblogs.com/lxg0/p/7774094.html module.exports与exports,export与export default之间的关系和区别 ...
- 理解nodejs的module模块儿
module 在 Node.js 模块系统中,每个文件都视为独立的模块,node在运行某个模块儿时会生成一个module对象 Module { id: '.', exports: 2, parent: ...
- NodeJS旅程 : module 不可忽略的重点
modules 模块的简介 Module 是Node.js中最重要的一个部分也是进行深度开发前的必修课.掌握Module才能真正理解NodeJS的精髓,你会发现从思路上会有极大的扩展. 学会写mod ...
- NodeJs FS 文件系统模块
1. fs.stat 检测是文件还是目录 fs.stat('html',function(err,stats){ if(err){ console.log(err); return false; } ...
随机推荐
- Oracle sql develpoer
Oracle SQL Developer是针对Oracle数据库的交互式开发环境(IDE) Oracle SQL Developer简化了Oracle数据库的开发和管理. SQL Develo ...
- 【JQuery】 ajax 无效的JSON基元
[如题]个人理解就是 你向传数据[josn格式]了,但是后台接受确不是json格式的 数据, 贴段代码 var strJson = '{ "usercode": "123 ...
- Yii 字段验证
关于验证的属性: $enableClientValidation:是否在客户端验证,也即是否生成前端js验证脚本(如果在form中设置了ajax验证,也会生成这个js脚本). $enableAjaxV ...
- openldap+phpadmin的搭建安装
1.概念介绍 LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.它是基于X.500标准的,但是简单多了并且可以根据 ...
- 【URAL 1297】Palindrome 最长回文子串
模板题,,,模板打错查了1h+QAQ #include<cmath> #include<cstdio> #include<cstring> #include< ...
- java中的this和super的作用和异同和C++中调用父类的构造函数
来源于:http://www.cnblogs.com/hasse/p/5023392.html 这几天看到类在继承时会用到this和super,这里就做了一点总结,与各位共同交流,有错误请各位指正~ ...
- jsrender for array 和for object语法
for array 循环数组 循环使用案例 定义数组数据 var data = { names: ["Maradona","Pele","Ronald ...
- bzoj1799: [Ahoi2009]self 同类分布
数位dp 先从1到162枚举各位数之和 s[i][j][k][l]表示i位数,第一位小于等于j,当前各位数字和为k,当前取模余数为l的方案数 然后脑补一下转移就行了 详见代码 #include < ...
- Spark 编程基础
1. 初始化Spark import org.apache.spark.{SparkContext, SparkConf} val conf=new SparkConf().setAppName(&q ...
- 【windows】跑大型程序时不要休眠和睡眠
win10系统. 为了节能,长时间没有操作操作系统会自动进入休眠模式. 先前设定了"控制面板\硬件和声音\电源选项\编辑计划设置",都设定为"从不",结果不起作 ...