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 ./server.coffee 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
./README.md # 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: http://nodetuts.com/tutorials/14-some-nodejs-tools.html
You can use
-x option set to
coffee. This will enable it to run script with right executable:
supervisor -x coffee your-script.coffee
Inspired by Lemming's answer.
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 Procfile.dev
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).
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.
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.
This recipe can be found in it's original form on Stack Over Flow.