Javascript Node.js:导出模块不工作
我在fwdCallToAgent.coffee有这个:Javascript Node.js:导出模块不工作,javascript,node.js,coffeescript,Javascript,Node.js,Coffeescript,我在fwdCallToAgent.coffee有这个: exports.fwdCallToAgent = (phone,res,req) -> 在server.coffee上: fwdCallToAgent = require './lib/fwdCallToAgent' 当我运行fwdCallToAgent时,我得到: 2011-11-13T09:49:08+00:00 app[web.1]: TypeError: object is not a function 我错过了什么
exports.fwdCallToAgent = (phone,res,req) ->
在server.coffee上:
fwdCallToAgent = require './lib/fwdCallToAgent'
当我运行fwdCallToAgent时,我得到:
2011-11-13T09:49:08+00:00 app[web.1]: TypeError: object is not a function
我错过了什么
谢谢
require
返回所需模块的导出
属性
您需要的是以下任一项
(A)
(B)
就个人而言,如果第二种方法是模块中唯一导出的函数,我建议使用第二种方法。
require
返回所需模块的exports
属性
您需要的是以下任一项
(A)
(B)
就个人而言,如果第二种方法是模块中唯一导出的函数,我建议使用它。Jan是正确的。使用CoffeeScript的解构赋值语法,您还可以编写
{fwdCallToAgent}=require./lib/fwdCallToAgent'
@Jan Kuca,谢谢。但是,当我将B)与module.exports=(phone,res,req)->User.find{account\u id:phone.account\u id},(err,User)->一起使用时,它无法识别“User”。这是另一个问题。您是否需要在fwdCallToAgent模块中定义了用户的模块<代码>变量用户=要求('./用户')代码>简是正确的。使用CoffeeScript的解构赋值语法,您还可以编写{fwdCallToAgent}=require./lib/fwdCallToAgent'
@Jan Kuca,谢谢。但是,当我将B)与module.exports=(phone,res,req)->User.find{account\u id:phone.account\u id},(err,User)->一起使用时,它无法识别“User”。这是另一个问题。您是否需要在fwdCallToAgent模块中定义了用户的模块<代码>变量用户=要求('./用户')代码>
// fwdETC.coffee
module.exports.fwdETC = function () { ... };
// server.coffee
fwdETC = require('./lib/fwdETC').fwdETC
// fwdETC.coffee
module.exports = function () { ... };
// server.coffee
fwdETC = require './lib/fwdETC'