I'm using Node.js and wanting to incorporate CoffeeScript into my workflow. I have two use-cases:
require()
CoffeeScript modulesFor case #1: I can just compile from .coffee
to .js
and require()
the .js
module, as a workaround.
For case #2: Right now I'm eval()
ing the output of coffee-script.compile()
.
Is there a better, more unified way to do this?
The coffee-script module registers its extension once required.
$ echo 'console.log "works"' > module.coffee
$ echo '
> require("coffee-script")
> require("./module")
> ' > test.js
$ node test.js
works
$ node
> require('coffee-script'); require('./module')
works
{}
Edit: This behaviour has changed with the relase of CoffeeScript 1.7.0. Now you need to do:
require('coffee-script/register');