If your looking to write your node.js apps in coffeescript and run them on heroku you’ve most likely read this http://stackoverflow.com/questions/6356267/can-i-run-coffeescript-in-heroku question. It left me scratching my head wondering how they’ve made it sound so complicated. In reality its quite simple and I’ll show you.
We will use this sample CS/express app for testing:
Heroku’s new cedar runtime stack uses the existence of a package.json to detect your node.js app so we’ll go ahead and oblige it with a simple one like so:
Remember to add node_modules to your .gitignore file to keep your slug size down.
Now. Heroku expects a Procfile to instruct their servers how to run your application. Again this is pretty straight forward and absolutely not specific to coffee-script.
You’ll not that we’re telling heroku to boot a webworker by running a currently non-existant file ‘boot.js’. This is where the magic happens that turns your app from a node.js app to a node.js app written in coffeescript.
We can simply include coffee-script which augments require to allow it to load coffeescript files. Done and done.
New library adding Jade support to requireJS. Allows you to include your templates and have a compiled function returned with the signature function(locals), which will return your html as string.
Before this great library there were two ways to supply your views with data.
Callback soup as demonstrated by TJ Holowaychuk:
Or long lonnnnng filter chains as demonstrated from one of my projects here:
My filter chains can be cleaned up to look like this:
Created a quick Alfred Theme with a 80% transparency and white background. Thought I’d share it here
Preview:

If your not using Alfred yet I highly recommend it. The powerpack is worth it for the terminal commands alone!
Vows is a great node.js BDD framework. It’s very fast, running your tests asynchronously when possible, or sequentially when controlled execution order is required.
Its incredibly readable and easy to write in its own right but why would that stop us from writing our vows in CoffeeScript!
Taking the example from the vows website
We can write the same in CoffeeScript as below
Personally I think the CoffeeScript version is much more readable with less line noise. I don’t know about you but this how I’ll be writing my tests for node.js going forward!
For more information on vows be sure to check out there site. They go into how to write much more complicated tests. Apply what you leaned here to keep your tests caffeinated!
So lately my attention has switched to Javascript. One thing that I noticed, especially coming from ruby, is that Javascript wasn’t a pretty language. Coffeescript looks to solve this by mashing some good bits of python and ruby together.
Lets look at some comparisons from http://coffeescript.org
A nested object in Javascript:
And now the same thing in Coffeescript:
It doesn’t solve world hunger or create everlasting piece but it does make it more fun to write javascript.
Now when I’ve been ranting about it to others in the industry they are skeptical that they should be writing in an intermediate language. All the while they comment about how much they love writing HAML and SASS. Now I know that there is a difference between Coffeescript and say Haml where one is being compiled into code and the other markup but the comparison stands.
One thing the naysayers have commented on is the fact that Coffeescript has a classical inheritance system built in. Real Javascript professionals don’t try to bend the language *mumble* *mumble* *scratch neck beard*
The great thing about Coffeescript is you don’t need to use those features which you distrust. And the compiler will only include the support code features that you use. Don’t want to use classical inheritance, no problem, don’t know what a list comprehension is* don’t worry just write Coffeescript as you would your Javascript albeit in a more comfortable syntax.
* List compregensions in Coffeescript rock!
Gives us an alert box with [2,3,4,5,6]