当前位置:网站首页>【Node学习笔记】chokidar模块实现文件监听
【Node学习笔记】chokidar模块实现文件监听
2022-07-06 18:43:00 【51CTO】
前言
开发云盘的时候,使用了 Node.js 的 chokidar 模块做本地文件监听,获取文件修改的触发事件,下面来给大家介绍一下涉及的知识点以及实现过程。
知识点
chokidar.watch(paths, [options]) 返回一个chokidar构造监听实例
参数:paths
一个字符串或者是一个数组,描述监听的文件或者文件夹的路径。
事件响应
.add 新增文件时触发
.addDir 新增文件夹的时候触发
.unlink 对应的文件的删除
.unlinkDir 对应的文件夹的删除
.change 文件内容改变时触发
.all(除了ready, raw, and error之外所有的事件类型)包含:add、addDir、unlink、unlinkDir、change
.ready 初始化完成
.raw 原始事件
.error 捕获error
.unwatch(path / paths) 停止监听传入文件/文件夹
.close() 从监视文件中移除/关闭所有侦听器
.getWatched() 返回此FSWatcher实例正在监视的文件系统上所有路径的对象
监听文件样例代码
注意事项
实现文件监听时,出现了系统兼容性的问题,有的电脑会出现文件修改不触发change,而是触发了 unlink 事件的情况。因此,在 unlink 事件里做了补充,当文件存在时触发更新。
以上就是本期关于 chokidar 模块实现本地文件监听的分享,希望能给大家带来帮助。
下期给大家分享更多实战中的点滴,如果大家对此感兴趣,欢迎各位关注、留言,大家的支持就是我的动力!
边栏推荐
- Web3的先锋兵:虚拟人
- 【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
- 压缩 js 代码就用 terser
- go swagger使用
- Integrated navigation: product description and interface description of zhonghaida inav2
- The empirical asset pricing package (EAP) can be installed through pypi
- 大咖云集|NextArch基金会云开发Meetup来啦!
- postgresql之整体查询大致过程
- 【LeetCode】Day97-移除链表元素
- The last line of defense of cloud primary mixing department: node waterline design
猜你喜欢
Flir Blackfly S 工业相机:配置多个摄像头进行同步拍摄
UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
Detailed explanation of line segment tree (including tested code implementation)
张平安:加快云上数字创新,共建产业智慧生态
Vingt - trois mille feuilles? "Yang mou" derrière l'explosion de la consommation végétale
Lidar: introduction and usage of ouster OS
Dall-E Mini的Mega版本模型发布,已开放下载
FLIR blackfly s industrial camera: explanation and configuration of color correction and code setting method
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
Several classes and functions that must be clarified when using Ceres to slam
随机推荐
Freeswitch dials extension number source code tracking
企业中台建设新路径——低代码平台
Seconds understand the delay and timing function of wechat applet
新一代云原生消息队列(一)
Pgadmin4 of PostgreSQL graphical interface tool
投资的再思考
C#/VB.NET 删除Word文档中的水印
组合导航:中海达iNAV2产品描述及接口描述
postgresql之integerset
Sensor: DS1302 clock chip and driver code
[C # notes] use file stream to copy files
The mega version model of dall-e MINI has been released and is open for download
Why am I warned that the 'CMAKE_ TOOLCHAIN_ FILE' variable is not used by the project?
4--新唐nuc980 挂载initramfs nfs文件系统
Infrared camera: juge infrared mag32 product introduction
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
freeswitch拨打分机号源代码跟踪
传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码
Flir Blackfly S USB3 工业相机:白平衡设置方法