watch-node
Watch files using the fsevents built into the Mac OS
Install
npm install watch-node
Usage
watch = require 'watch-node'watch './src'consolelog "File changed: "
Example: Automatically Restart Node Server
Here's a cake
task to automatically restart the node server when it changes. Customize it however.
(JavaScript version of the example)
require 'child_process'fs = require 'fs'path = require 'path'Shift = require 'shift'watch = require 'watch-node'serverPath = "example/server.js"task 'auto-reload'->watch pathdirnameserverPathif filematchserverPathexec 'ps aux | grep node'lines = stdouttoStringsplit"\n"for line in linesif linematchserverPathmatch = linematch/[^ ]+ +/if matchpid = match1exec "kill -2 "exec "node "consolelog "Server restarted... node "
Example: Automatically Compile CoffeeScript, Stylus, Less, etc.
Here's a cake
task to watch JS/CSS templates and recompile them. It works with any file.
fs = require 'fs'path = require 'path'watch = require 'watch-node'Shift = require 'shift'task 'watch''Compile asset templates'->watch './src'fsreadFile file'utf-8'throw error if errorinputExtension = pathextnamefileoutputExtension = switch inputExtensionwhen ".coffee"".ejs" then ".js"when ".styl"".less"".sass" then ".css"engine = Shiftengine extensionoutputPath = filereplace/^\.\/src/"./lib"replace"$"outputExtensionenginerender inputfswriteFile outputPathoutput