Alex Rivera | Logout

NodeJS + CoffeeScript, render coffeescript compiled js on request

Asked 2011-03-04T15:41:18.900
20

What I would like to do is add the following to me already running coffeescript written server

app.get '/test.js', (req, res) ->
    render coffee somecoffeefile.coffee

Is something like this possible with NodeJS, Express, and Coffeescript?

Thanks!

Jose

Edit
Report

2 Answers

12
CoffeeScript = require 'coffee-script'

app.get '/test.js', (req, res) ->
  render CoffeeScript.compile coffeeSourceCode
answered 2011-03-04T17:11:00.097
2

If you would like to use a great existing plugin I would recommend Trevor Burnham's Connect-Assets. It helps compiling, minifying and concatenating .js and .coffee-files and optimizes how the files are being served (a far-future expires header with invalidation using the file's md5-hash). Well written plugin.

answered 2012-04-16T16:04:15.390

Your Answer