当前位置:网站首页>[node learning notes] the chokidar module realizes file monitoring
[node learning notes] the chokidar module realizes file monitoring
2022-07-07 02:35:00 【51CTO】
Preface
When developing cloud disk , Used Node.js Of chokidar The module monitors local files , Get the trigger event of file modification , Now let's introduce the knowledge points involved and the implementation process .
Knowledge point
chokidar.watch(paths, [options]) Return to one chokidar Construct listening instance
Parameters :paths
A string or an array , Describe the path of the monitored file or folder .
Event response
.add Triggered when adding a file
.addDir Triggered when adding a folder
.unlink Delete the corresponding file
.unlinkDir Delete the corresponding folder
.change Triggered when the file content changes
.all( except ready, raw, and error All event types except ) contain :add、addDir、unlink、unlinkDir、change
.ready Initialization complete
.raw Original event
.error Capture error
.unwatch(path / paths) Stop listening for incoming files / Folder
.close() Remove from the monitoring file / Close all listeners
.getWatched() Back here FSWatcher Objects of all paths on the file system being monitored by the instance
Sample code of listening file
matters needing attention
When realizing file listening , There is a problem of system compatibility , Some computers will not trigger file modification change, It triggered unlink The circumstances of the incident . therefore , stay unlink Added in the event , Trigger update when file exists .
That's what this issue is about chokidar The module realizes local file listening The share of , I hope I can help you .
In the next issue, I'll share more details about the actual combat , If you're interested in that , Welcome to pay attention to 、 Leaving a message. , Your support is my motivation !
边栏推荐
猜你喜欢
随机推荐
Lumion 11.0软件安装包下载及安装教程
测试优惠券要怎么写测试用例?
MATLB|具有储能的经济调度及机会约束和鲁棒优化
How to build a 32core raspberry pie cluster from 0 to 1
Draco - glTF模型压缩利器
实施MES管理系统时,哪些管理点是需要注意的
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
Compress JS code with terser
Apifox, is your API interface document rolled up like this?
The cities research center of New York University recruits master of science and postdoctoral students
企业中台建设新路径——低代码平台
postgresql之整體查詢大致過程
Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
[paper reading | deep reading] dngr:deep neural networks for learning graph representations
所谓的消费互联网仅仅只是做行业信息的撮合和对接,并不改变产业本身
C语言练习题_1
pgpool-II和pgpoolAdmin的使用
进程管理基础
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
[C # notes] reading and writing of the contents of text files