Skip to content

Commit fff672d

Browse files
committed
[api] simplest possible file watcher (ref #41)
1 parent d658ee3 commit fff672d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/forever/monitor.js

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var util = require('util'),
1212
events = require('events'),
1313
spawn = require('child_process').spawn,
1414
winston = require('winston'),
15+
watch = require('watch'),
1516
forever = require('../forever');
1617

1718
//
@@ -364,6 +365,21 @@ Monitor.prototype.kill = function (forceStop) {
364365
return this;
365366
};
366367

368+
//
369+
// ### function watch ()
370+
// Starts watching directory tree for changes.
371+
//
372+
Monitor.prototype.watch = function () {
373+
var self = this;
374+
375+
watch.createMonitor(process.cwd(), {ignoreDotFiles: true}, function (monitor) {
376+
monitor.on('changed', function (f, curr, prev) {
377+
self.info('restaring script because ' + f + ' changed');
378+
self.restart();
379+
});
380+
});
381+
}
382+
367383
//
368384
// ### @private function _getEnv ()
369385
// Returns the environment variables that should be passed along

0 commit comments

Comments
 (0)