I have a node.js app written in CoffeeScript.
I'm wondering what is needed in order to host the app on Heroku.
Thanks
Due to the updates with Heroku, it now allows for an npm
installation of the coffee-script
source. The answer below was a work-around before Heroku fully supported node.js
. For a better solution currently, please see the higher rated answer explaining how to simply use coffee-script
from npm
on Heroku.
To be honest the best way would be to compile it before hand using coffee -c filename
like Peter suggested, but I wonder if you could have a sort of 'preload' preload.js
that will call the scripts using coffeescript
as a node_module
then compile() the script to be used. That way you can use them natively in node on heroku without dealing with extra files in your repo.
npm install coffee-script
Then in the inital app, write it in javascript and call the *.coffee
files using coffee's compile function:
var coffee = require('coffee-script');
coffee.compile('./server.coffee');
// could be coffee.run(file) instead, not sure
and in yourapp.coffee
try
console.log 'It worked!'
I'm not sure if this would work, or if that's even the proper syntax for that function. https://github.com/jashkenas/coffee-script/blob/master/lib/coffee-script.js#L24
If you're asking about doing it in ruby, here's this:
Walkthrough on how to use coffeescript in rails on Heroku: http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/
It suggests using bistro_car ( https://github.com/jnicklas/bistro_car )
gem install bistro_car
mkdir -p app/scripts
and adding it to your Rails conf/environment.rb
config.gem 'bistro_car'
If I find something else or another way to natively run *.coffee
javascript apps, I'll update this answer but hopefully this will give you some idea on how to get it to work.
Here are a couple more examples, but they all seem to be using ruby vs node.js as well:
http://forrst.com/posts/Doing_CoffeeScript_on_Heroku_a_Ruby_gem-OBk http://www.tangiblecolors.com/first-steps-with-coffeescript-and-how-to-use
Hope this helps a little bit.