Debugging CoffeeScript on NodeJS in IntelliJ IDEA 12

I have spent some time figuring out how to befriend IDEA 12 with CoffeeScript. The official docs are a little bit outdated on this topic.

As a result I can compile and debug coffee files in NodeJS project developing it in IDEA (WebStorm will suit too, I believe).

CoffeeScript + NodeJS + IDEA magic

I will describe how to configure the stuff on Mac Os X. I use homebrew as a package manager. The process is very similar on any other OSes (except, maybe, Windows).

To have the magic up and running we will need:

  1. NPM installed.
  2. CoffeeScript plugin (bundled with IDEA).
  3. File Watchers plugin

    Jet Brains custom plugin, needs explicit installation.

  4. CoffeeScriptRedux npm module.

    This is an alternative coffee compiler. It is positioned as "CoffeeScript 2.0". Actually, you can setup the whole magic using standard compiler with different flags, but I used CSR before CoffeeScript 1.7 was released. Note: you cannot have both coffee-script and coffee-script-redux modules, cause their executables are both called coffee

    Install it using sudo npm install -g coffee-script-redux.

  5. Add two file watchers. Use Coffee Script and Coffee Script Source Map templates.

    Actually you can use only one template, but CSSM template adds a file masking ability, i.e. visually the generated files will nicely reside in collapsible subtree of your coffee file.

  6. Main part. Configure file watchers as shown on the images below.

    • Arguments for compiler: --js -i $FileName$ --source-map-file $FileNameWithoutExtension$
    • Check the option create output file from stdout

CoffeeScriptRedux configuration

Sourcemap configuration

Is it working?

On any file modification you should see two generated files : <filename>.js and <filename>

The generated js file must contain something like this:


The last point: you should run your server using only IDEA's nodejs run configuration.

Have fun with you CoffeeScript!