Coffeescript and node-supervisor together?


I'm using coffeescript with --watch option to rebuild javascript on changes to .coffee files.

Is it safe to combine that with node-supervisor to restart Node on changes to the compiled javascript?

I'm worried it won't be robust because of atomicity when coffeescript is recompiling multiple files. node-supervisor could jump the gun and restart Node on detecting the first filesystem change. Is it robust enough to realize there were additional changes while it was busy restarting Node?

Is there a better way? Ideally I'd have only one filesystem watcher recompile my coffeescript and restart node.

Problem courtesy of: Nils


You can use nodemon, it even has a delay feature (to restart server after a number of seconds have passed), for example:

nodemon --debug ./ 80

Another good feature of nodemon is ignoring files, example:

# this is my ignore file with a nice comment at the top

/vendor/*     # ignore all external submodules
/public/*     # static files
./   # a specific file
*.css         # ignore any CSS files too

Other than that, read the documentation on the github repo and watch this Nodetuts video about nodemon:

Solution courtesy of: alessioalex


You can use supervisor with -x option set to coffee. This will enable it to run script with right executable:

supervisor -x coffee

Inspired by Lemming's answer.

Discussion courtesy of: Ivan Nevostruev

My foreman centric solution looks like this:

web: ./node_modules/supervisor/lib/cli-wrapper.js -n exit server.js
watch: ./node_modules/iced-coffee-script/bin/coffee --watch --compile server.iced

and then merely foreman start -f

Then gitignore the resulting .js files. I like this approach because it keeps a constantly-updating vanilla JS file alongside my .iced files, so I can doublecheck my work as I go (I definitely make mistakes in coffeescript that I might not in vanilla).

Discussion courtesy of: Vincent Woo

Create a JavaScript launcher, i.e. run.js, like this:


Then run this file with supervisor and appropriate options:

supervisor -e "node|js|coffee" run.js

This worked well for me on Windows.

Discussion courtesy of: Lemming

In some of my Cakefiles, such as the one for connect-assets, I do the watching myself and simply spawn coffee -co lib src each time something changes, then restart the server when that child process finishes. That gets around the atomicity issue. If every .coffee file changes at once (or if you upgrade the coffee runtime), all of the JS files will update at once as well.

Discussion courtesy of: Trevor Burnham

This recipe can be found in it's original form on Stack Over Flow.