当前位置:网站首页>【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 模块实现本地文件监听的分享,希望能给大家带来帮助。
下期给大家分享更多实战中的点滴,如果大家对此感兴趣,欢迎各位关注、留言,大家的支持就是我的动力!
边栏推荐
- 3--新唐nuc980 kernel支持jffs2, Jffs2文件系统制作, 内核挂载jffs2, uboot网口设置,uboot支持tftp
- [server data recovery] data recovery case of a Dell server crash caused by raid damage
- 3D laser slam: time synchronization of livox lidar hardware
- 长安链学习笔记-证书研究之证书模式
- Chang'an chain learning notes - certificate model of certificate research
- [C # notes] use file stream to copy files
- GEE升级,可以实现一件run tasks
- C#/VB.NET 删除Word文档中的水印
- Metaforce force meta universe development and construction - fossage 2.0 system development
- Real project, realized by wechat applet opening code (end)
猜你喜欢
Douban average 9 x. Five God books in the distributed field!
Schedulx v1.4.0 and SaaS versions are released, and you can experience the advanced functions of cost reduction and efficiency increase for free!
红外相机:巨哥红外MAG32产品介绍
Flir Blackfly S USB3 工业相机:计数器和定时器的使用方法
Infrared camera: juge infrared mag32 product introduction
1个月增长900w+播放!总结B站顶流恰饭的2个新趋势
UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
1--新唐nuc980 NUC980移植 UBOOT,从外部mx25l启动
随机推荐
Use of pgpool II and pgpooladmin
pgpool-II和pgpoolAdmin的使用
FLIR blackfly s industrial camera: configure multiple cameras for synchronous shooting
压缩 js 代码就用 terser
遇到慢SQL该怎么办?(下)
FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
红外相机:巨哥红外MAG32产品介绍
A new path for enterprise mid Platform Construction -- low code platform
String or binary data will be truncated
人脸识别应用解析
长安链学习笔记-证书研究之证书模式
Flir Blackfly S USB3 工业相机:计数器和定时器的使用方法
如何从0到1构建32Core树莓派集群
【森城市】GIS数据漫谈(二)
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
[paper reading | deep reading] dngr:deep neural networks for learning graph representations
传感器:DS1302时钟芯片及驱动代码
【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例