Beginners guide to using CoffeeScript on Windows with node.js

! Warning: this post hasn't been updated in over three years and so may contain out of date information.

coffeescript logoWith Adobe’s relegation of Flash to the web sidelines last November, I finally decided that maybe I should take a serious look at JavaScript. One of the first things I discovered was a beautifully simple, elegant and lightweight “syntactic sugar” language built on JavaScript called CoffeeScript. So I figured I’d install the compiler and get experimenting…

Sometimes I figure things wrong and this was one such occasion. The CoffeeScript compiler is written in JavaScript, so to run it as a command line tool, one needs a command line JavaScript environment, which can be easier said than done. The obvious choice is node.js, but until recently, node.js didn’t work too well on Windows. So if you wanted to run the CoffeeScript compiler, doing so via node.js sat somewhere between impossible and very difficult. There are other options involving ruby and the like, but they are all complex to set up. I wanted a simple way of compiling CoffeeScript to JavaScript. That simple way came with recent releases of node.js, which finally offer good Windows support.

First of all, visit the node.js download page and download and install the Windows installer. This will install both node.js and the npm package manager as well as updating your Path variable with both the node.js folder and the npm package manager’s module install folder. Don’t forget to log out and in again for changes to %Path% to take effect!

To test the installation, open a cmd window and type node -v, which should print something like v0.6.9. Note that the exact number may vary as node.js is an active project with frequent releases. If all is OK, the next step is to install CoffeeScript. To do so, type npm install -g coffee-script. This should result in something like the following being output:

To test all is OK, run coffee -bpe "alert i for i in [0..10]" and it should output:

If so, you now have a functional CoffeeScript compiler running on your machine and can start experimenting with this exciting new language.

8 thoughts on “Beginners guide to using CoffeeScript on Windows with node.js

  1. THANK YOU!!

    I was about to mock about with a windows/ubuntu dual-boot solution, but this was so much easier.

    Now to make some coffee(-script) 😉

  2. I get the same output but I don’t think this is right because it makes no sense if you read the for loop. It’s saying i = _i which is = to 0 then if _i is less than or equal to 10 (what about i?) then that crazy looking increment.

    It works but it’s ridiculously redundant with the extra variable.

    I’m getting this output but also have other issues like compile error for ‘->’ so I think it’s buggy in windows

  3. How I can use it in phpstorm or Sublime text. Not sure but I thing it’s support cmd kind of functionality itself.

  4. thanks David.. just starting with coffeescript, from flash.. heading towards angularjs, ext js and the like.. your post has saved me a lot of time. all the best with it !

Comments are closed.