使用“咖啡”而不是“节点”命令 [英] Use "coffee" instead of "node" command in production
问题描述
我有一个正在运行express.js的app.js。
I have an app.js that is running express.js.
我想将代码转换为coffeescript并考虑创建一个app.coffee到app.js,所以我可以用node app.js运行它。
I wanna convert the code to coffeescript and thought about to create a app.coffee that I compile to app.js so I can run it with "node app.js".
但是它打我,我可以写在app.coffee文件,并运行它与咖啡app.coffee。
But then it hit me that I could just write that file in app.coffee and run it with "coffee app.coffee".
这是更好的方法吗?我可以在生产中使用咖啡运行服务器吗?
Is this a better way? Can I run the server with "coffee" in production?
推荐答案
我使用它。
我可以看到两个原因,你想使用app.js包装器。
I can see two reasons why you would want to use app.js wrapper.
- 您要使用CoffeeScript的本地安装。 (应用程式之间的不同版本)
- 您想使用预设的 npm start 启动服务器:)请参阅 npm help scripts
- You want to use local installation of CoffeeScript. (different versions between apps)
- You want to use the default npm start to launch your server :) See npm help scripts
哦,你不需要编译它。您可以使用像这样的包装器透明地编译咖啡文件:
Oh, and you don't need compile it. You can use a wrapper like this which compiles the coffee file transparently:
server.js:
server.js:
require('coffee-script').register();
require("./yourcoffeeapp.coffee");
如果您想在一些不直接支持的托管环境中使用CoffeeScript,此封装技术特别有用CoffeeScript命令。如Cloud 9 IDE。不需要编译js文件。
This wrapper technique is especially useful if you want to use CoffeeScript in some hosted environments that does not directly support the CoffeeScript command. Such as Cloud 9 IDE. No need to fiddle with compiled js-files.
这篇关于使用“咖啡”而不是“节点”命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!