表达需要来自其他文件的URL的js

时间:2013-03-19 13:34:39

标签: node.js express coffeescript

我有这个:

./ urls.coffee

urlConfig = [
    ["/", (req, res) -> res.send "hello world"]
]
module.exports = urlConfig

./ utils的/ helpers.coffee

getUrl = (app, urlconfig)->
    for url in urlconfig
       app.get url[0], url[1]
module.exports.getUrl = getUrl    

./ app.coffee

express = require "express",
app = express();
helper = require "./utils/helper"
urls = require "./urls"

helper.getUrl app, urls

我正在尝试将urlapp.coffee分开,方法是在另一个文件url.coffee中定义它。

但是回调无法接收(req, res) args,错误是: req is not defined,但如果回调没有收到args,它可以正常工作。有人有任何想法或建议吗?

1 个答案:

答案 0 :(得分:0)

不应该是这样的:

var express = require "express",
helper = require "./utils/helper"

app = express();
app.get = helper.getUrl