Minh Thành Minh Thành - 6 months ago 18
Node.js Question

How to run coffeescript file with nodejs?

I use coffee script to writing my node.js app. When I write an .coffeescript file and run it. It will compile into top-level function javascript and this make my code didn't run.

Ex:

app.coffee

console.log "Hello world";


Will automatically compile into

(function() {
console.log("Hello world");
}).call(this)


And this make node app.coffee didn't run.

Can you help me whenever I run
node app.coffee
it will compile my coffeescript with
-bare
option?

Answer

Do you run cofeescript with node app.coffee?

According to answers to this question it is impossible. You have to either compile it first and then run, i.e.

coffee -c app.coffee
node app.js

or use the coffee to run it for you, i.e.

coffee app.coffee

Nevertheles, I can't see how the wrapper function generated by coffee could "make the app did not run".