码迷,mamicode.com
首页 > Web开发 > 详细

nodejs中监听文件更改(转)

时间:2019-06-03 21:28:28      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:join   ges   nbsp   eve   ida   cti   pat   initial   div   

https://www.jianshu.com/p/23b5e604268d

nodejs下监听文件更改的插件

  var path = require(‘path‘)
  var Chokidar = require(‘chokidar‘);
  var watcher = Chokidar.watch([path.join(__dirname, ‘../src‘)], {
    // ignored: /(^|[\/\\])\../, 
    persistent: true,
    usePolling: true,
  });
  var log = console.dir.bind(console);
  var watchAction = function({event, eventPath}){
    log(`Has been ${event}ed, file: ${eventPath}`);
    // 这里进行文件更改后的操作
  }
  watcher
  .on(‘ready‘, () => log(`Initial scan complete. Ready for changes.`))
  .on(‘add‘, path => log(`File ${path} has been added`))
  .on(‘change‘, path => watchAction({event: ‘change‘, eventPath: path}))
  .on(‘unlink‘, path => watchAction({event: ‘remove‘, eventPath: path}));

 

nodejs中监听文件更改(转)

标签:join   ges   nbsp   eve   ida   cti   pat   initial   div   

原文地址:https://www.cnblogs.com/samxiong/p/10970053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!