Installing and using Coffee-Script with Assetic on Windows

15. November 2011 in Assetic, CoffeeScript, Symfony2

There are a lot of poor souls that are forced to use Windows as an OS for their daily development job. I’m one of them. I heard even of people enjoying working on Windows ;) There is one thing in common for them: Using cutting edge tools like CoffeeScript, node.js and others isn’t working easily out of the box most of the time. But in case of CoffeeScript there is good news. Since the release of Node.JS 0.6 with native windows support everything is working pretty fine. Here is what you will need to do to get it working.

Installing Node.JS

The best way using CoffeeScript is the installation via Node.js. The setup of Node.js can easily be done with the new Windows-Installer package that is available on the project site. There is nothing special here. After node.js is installed you will need to setup the node.js package manager (npm). You willneed to have a Git-Client installed on your machine. The best you can get is msysgit which brings a git bash console. Please make sure you have version 1.7.6 or newer installed on your PC. Open up a Git-Bash console and change to the folder you want to install npm (C:\Program Files for example). After that execute the following three commands:
[crayon lang=sh]> git config –system http.sslcainfo /bin/curl-ca-bundle.crt
> git clone –recursive git://
> cd npm
> node cli.js install npm -gf
You have now the node.js package manager installed.

Installing CoffeeScript

Installing CoffeeScript is now a piece of cake. Just use the following command:
[crayon lang=sh]> npm install -g coffee-script[/crayon]
The -g switch ensures that your CoffeeScript installation is available system-wide. If everything went right you can now start the CoffeeScript commandline tool from the console.

Coffee-Script commandline

If you need tutorials or reference material for CoffeeScript here is what I found useful:

Using Coffee-Script with Assetic

Working with Coffee-Script and the commandline compiler leads to uncomfortable development process. But there is light at the end of the tunnel. As with all assets Assetic will be of great help when using Coffee-Script files in your Symfony project. The AsseticBundle is part of the Symfony2 Standard Edition so there is no need to install anything. You just have to do some configuration work ahead. This is done in the app/config/config.yml file. There you have to add a filter for CoffeeScript.
By default this filter is looking at fixed folders for the bin files of CoffeeScript and node.js. These paths are unix-ones. So we need to configure the paths, so they correspond with your installation folders.
bin: c:/nodejs/bin/node.exe
node: c:/npm/bin/npm.exe
From now on there is no difference in using the CoffeeScript files with Assetic compared to unix systems. Here is how to use them in Twig-Templates.
[crayon lang=php]
{% javascripts filter=”coffee”

{% endjavascripts %}

If you need more infos on how to use CoffeeScript with Assetic take a look at the Blog of Richard Miller

1 response to Installing and using Coffee-Script with Assetic on Windows

  1. Timo, thanks for this write up on getting CoffeeScript installed on Windows. I followed you instructions and still have a few questions/issues:

    The Nodejs installer (node-v0.6.5.msi) from the project site installs nodejs files in my Program Files (x86) (I am using a W7 64 bit). It appears to me that it already has the npm git repo installed with it. For my system:, C:\Program Filee (x86)\nodejs\node_modules/npm. Then is use the “node cli.js install npm -gf”. It installs the npm files “C:c\Users\Adam\local\” When I do the npm install then it gives me npm.cmd there with is own node_module folder again with the full npm library. When I install CoffeeScript, it then installs a coffee.cmd in the same “C:\c\Users\Adam\local\folder. Am I doing something completely wrong?

    For Assectic, then which files should I be using since there isn’t a .exe for npm or coffee. Also, looking at Richard Miller’s blog about Coffee and Assectic’s app/config.yml configuration, he uses the actual coffee script file for the “bin:” and then the actual node script for the “node”. Whereas you use the node.exe for the “bin:” and npm.exe for the “node:” setting. Is this correct for Windows?

Leave a reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>