And thirdly, because the creator of Ruby on Rails, David Heinemeier Hansson, says so :-). The upcoming 3.1 release of Ruby on Rails will include CoffeeScript in the box, which means that other web frameworks will probably also add support for CoffeeScript in the future.
Enough with the marketing talk already. Let’s have a quick look at how to get CoffeeScript up and running. For starters, you need to have Node.js and npm installed. Check out the installation guide or Matthew Podwysocki's on how to get Node.js up and running on Windows using Cygwin.
When you have node.js all set up, you can simply use the following command to install the CoffeeScript compiler using npm:
npm install -g coffee-script
Now that we have CoffeeScript installed, we can compile .coffee files into .js files or we can use the interactive REPL. Let’s go for the canonical “Hello Pluto” example here and create a file named hello.coffee with the following code:
coffee -p hello.coffee
or we can use this next command to compile our hello.coffee file to a corresponding hello.js file at the same location in the file system:
coffee -c hello.coffee
console.log 'Hello CoffeeScript'
We’re also able to keep the CoffeeScript compiler running with the –w, --watch command-line option. This basically lets the CoffeeScript compiler watch for the specified .coffee files and recompile them as soon as they’re changed.
coffee -cw hello.coffee
Until next time.