Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 783
Nils Avatar asked Dec 23 '11 17:12

Nils


2 Answers

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

require('coffee-script');
require('./launch');

Then run this file with supervisor and appropriate options:

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

This worked well for me on Windows.

like image 148
Lemming Avatar answered Oct 12 '22 08:10

Lemming


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

like image 39
alessioalex Avatar answered Oct 12 '22 10:10

alessioalex