我可以直接从 node.js 运行 .coffee 文件吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7337495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:33:07  来源:igfitidea点击:

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

node.jscoffeescript

提问by Shamoon

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?

我正在做一些教程,我正在用 CoffeeScript 编写所有内容。然后我必须编译成 JS 然后在 node.js 中执行。有什么办法可以直接做到吗?

回答by yujingz

Yes you can.

是的你可以。

coffee source.coffee -n

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

它将直接运行 Node 而不生成任何 .js 文件。

Reference

参考

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

更新: Coffee 现在也支持--nodejs. 上面做的一样

coffee source.coffee --nodejs

But yeah, -nis way shorter.

但是,是的,-n要短得多。

回答by driis

If you have npm, use it to install coffeescript from a node prompt: http://jashkenas.github.com/coffeescript/#installation

如果您有 npm,请使用它从节点提示安装咖啡脚本:http://jashkenas.github.com/coffeescript/#installation

Then, from the node prompt, you can simply use the coffee command to execute:

然后,在节点提示符下,您可以简单地使用 coffee 命令来执行:

coffee <yourcoffeescriptfile>.coffee

And, to just compile, pass the -cflag:

并且,为了编译,传递-c标志:

coffee -c <yourcoffeescriptfile>.coffee