Skip to content

Instantly share code, notes, and snippets.

@tsgautier
Created November 21, 2012 21:12
Show Gist options
  • Save tsgautier/4127755 to your computer and use it in GitHub Desktop.
Save tsgautier/4127755 to your computer and use it in GitHub Desktop.
auto-refresh in an express/angular project
watcher.watch __dirname + '/../public'
watcher.watch __dirname + '/../views'
io.sockets.on 'connection', (socket) ->
watcher.on 'changed', -> socket.emit 'cmd:refresh'
function products($rootScope, $scope, $http, socket) {
socket.on("cmd:refresh", function() { window.location.reload(true); });
class Watcher extends EventEmitter
constructor: ->
@watchers = []
watch: (directory) =>
fs.exists directory, =>
finder = findit.find directory
watchit = (f) =>
@watchers.push fs.watch f, => @emit 'changed'
finder.on 'directory', watchit
finder.on 'file', watchit
stop: =>
_.each @watchers, (w) -> w.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment