当前位置:网站首页>【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 模块实现本地文件监听的分享,希望能给大家带来帮助。
下期给大家分享更多实战中的点滴,如果大家对此感兴趣,欢迎各位关注、留言,大家的支持就是我的动力!
边栏推荐
- [leetcode] day97 remove linked list elements
- argo workflows源码解析
- Lombok同时使⽤@Data和@Builder 的坑
- FLIR blackfly s usb3 industrial camera: how to use counters and timers
- 张平安:加快云上数字创新,共建产业智慧生态
- Halcon instance to opencvsharp (C openCV) implementation -- bottle mouth defect detection (with source code)
- 6 seconds to understand the book to the Kindle
- Blackfly s usb3 industrial camera: buffer processing
- freeswitch拨打分机号源代码跟踪
- [paper reading | deep reading] graphsage:inductive representation learning on large graphs
猜你喜欢
![[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity](/img/21/59c4d61b22e7d021b7a72a64a16b48.png)
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity

FLIR blackfly s usb3 industrial camera: white balance setting method

强化学习如何用于医学影像?埃默里大学最新《强化学习医学影像分析》综述,阐述最新RL医学影像分析概念、应用、挑战与未来方向

Vingt - trois mille feuilles? "Yang mou" derrière l'explosion de la consommation végétale

张平安:加快云上数字创新,共建产业智慧生态

Douban average 9 x. Five God books in the distributed field!

String or binary data will be truncated

Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem

Stm32f4 --- general timer update interrupt

UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
随机推荐
组合导航:中海达iNAV2产品描述及接口描述
【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
FLIR blackfly s usb3 industrial camera: white balance setting method
云原生混部最后一道防线:节点水位线设计
Flir Blackfly S USB3 工业相机:计数器和定时器的使用方法
STM32F4---PWM输出
长安链学习笔记-证书研究之证书模式
压缩 js 代码就用 terser
Draco - gltf model compression tool
Freeswitch dials extension number source code tracking
[paper reading | deep reading] dngr:deep neural networks for learning graph representations
pgpool-II和pgpoolAdmin的使用
C#/VB.NET 删除Word文檔中的水印
Schedulx v1.4.0 and SaaS versions are released, and you can experience the advanced functions of cost reduction and efficiency increase for free!
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
Overall query process of PostgreSQL
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
Argo workflows source code analysis