coffeescript要求模块挂起

时间:2014-01-07 22:01:59

标签: express coffeescript

民间,   调用http://localhost:3000/file/sync

时会挂起以下内容

app.coffee:

express = require('express')
jsonFun = require('./jsonFun')
app = express()

exports.app = app

app.configure () ->
    app.set 'view engine', 'jade'
    app.use express.bodyParser()
    app.use express.logger('dev')
    app.use app.router


app.get '/hello/:name', (req, res) ->
    res.send 'hello ' + req.params.name

app.get '/file/sync', (req, res) ->
    jsonFun.syncJSON



app.listen 3000
console.log "Listening on 3000..."

jsonFun.coffee:

fs = require 'fs'

module.exports.syncJSON = ->
    console.log 'syncJSON Called'
    res.send 'json file results ' + req

module.exports.asyncJSON = ->
    console.log 'asyncJSON Called'

包含jsonFun.coffee文件的正确语法是什么,并传递req,res并让它返回响应?谢谢!

2 个答案:

答案 0 :(得分:2)

要在CoffeeScript中调用函数,需要参数或parens:

# this is a call
ok(1)
# this is a call, too
ok 1
# this is a parameter-less call
ok()
# this is just a variable access
ok

只需使用.syncJSON()

即可

答案 1 :(得分:0)

解决:

app.get '/hello/:name', (req, res) ->
    res.send 'hello ' + req.params.name

module.exports.syncJSON = (req, res)->
    console.log 'syncJSON Called'
    res.send 'json file results '