Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run a .coffee file directly from node.js?

I'm doing some tutorials and I'm writing everything in CoffeeScript. I then have to compile to JS then execute in node.js. Is there any way to do it directly?

like image 390
Shamoon Avatar asked Sep 07 '11 16:09

Shamoon


People also ask

How do you run a .JS file in node JS?

You can Run your JavaScript File from your Terminal only if you have installed NodeJs runtime. If you have Installed it then Simply open the terminal and type “node FileName. js”. If you don't have NodeJs runtime environment then go to NodeJs Runtime Environment Download and Download it.

What is a .coffee file?

JavaScript file written in CoffeeScript, a programming language that compiles and transcompiles to JavaScript; saved in a text format and contains code that is similar to JavaScript, but modified to be more readable. CoffeeScript's aim is to enhance JavaScript's brevity and readability.


1 Answers

Yes you can.

coffee source.coffee -n 

It will run Node directly without generating any .js files.

Reference

Update: Coffee now also supports --nodejs. The above does the same as

coffee source.coffee --nodejs 

But yeah, -n is way shorter.

like image 142
yujingz Avatar answered Oct 15 '22 04:10

yujingz