Minh Thành Minh Thành - 9 months ago 45
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.



console.log "Hello world";

Will automatically compile into

(function() {
console.log("Hello world");

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


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".