2014-01-07 2 views
0

Folks, следующие зависания при вызове http://localhost:3000/file/syncCoffeeScript требуется модуль висит

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 и вернуть ответы? Благодаря!

+0

Почему нижний предел? – Cmag

ответ

2

Для вызова функции в 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()

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 ' 
Смежные вопросы