如何构建一个Cakefile来运行node.js

时间:2013-09-17 19:40:33

标签: javascript node.js coffeescript

目前正在通过“Teach Yourself Node.js in 24 Hours”,我希望在CoffeeScript而不是JavaScript中尽可能多地执行代码。

安装coffee-scriptnode

我还是蛋糕开发系统的新手 - 有人可以指点我如何组装一个Cakefile来加载一个简单的服务器,比如server.coffee来运行demo码?

1 个答案:

答案 0 :(得分:2)

您可以在Cakefile中使用Node's API的任何部分,包括child_process来执行命令。

使用child_process.spawn(),您应该可以使用:

task 'server', 'Start up the server', (options) ->
  spawn = require('child_process').spawn
  child = spawn 'coffee', [ "#{__dirname}/server" ]

  child.on 'error', console.error
  child.on 'exit', -> console.log('exit')