咖啡脚本需要模块挂起



伙计们, 调用http://localhost:3000/file/sync时,以下内容挂起

应用咖啡:

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 并让它返回响应的正确语法是什么? 谢谢!

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

# 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()

已解决:

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 '

最新更新