Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
197
rated 0 times [  199] [ 2]  / answers: 1 / hits: 29763  / 14 Years ago, sat, january 22, 2011, 12:00:00

I'm using Node.js and wanting to incorporate CoffeeScript into my workflow. I have two use-cases:




  1. I want to be able to write JavaScript files which require() CoffeeScript modules

  2. I want to be able to load CoffeeScript modules from within the node REPL



For 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?


More From » node.js

 Answers
2

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');

[#94098] Thursday, January 20, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adrienkeithr

Total Points: 503
Total Questions: 126
Total Answers: 110

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
;