• 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.
    
    
  • 相关阅读:
    使用JavaScript实现新闻滚动效果
    ArcGIS Server建立缓存(切图)原理解析[图解] (转载)
    tp5 中使用自定义扩展类和函数
    phpstorm 配置点右上角浏览器图标时用浏览器打开当前页面
    PHP命名空间(Namespace)的使用简介
    linux 查看和修改文件时间
    头像上传uploadPreview插件
    富文本编辑器 kindEditor
    linux 计划任务 crontab 简单用法
    阿里 短信 使用方法
  • 原文地址:https://www.cnblogs.com/mayidudu/p/5872396.html
Copyright © 2020-2023  润新知