Node.jscallback调用两次

我为node.js使用sendgrid库。 目前有一个callback,它被炒了两次。

@invite = (email, agencyId, callback) -> (app.get 'agencies').findOne {_id: agencyId}, {name:1}, (error, agency) -> sendgrid.send { to: email, from: 'yamil.asusta@upr.edu', subject: "You have been invited to #{agency.name}", html: "<html><body>Have fun</a></body></html>" }, (success, message) -> console.log arguments if success console.log callback callback() else console.log message 

这是我从控制台得到的

 { '0': true, '1': undefined } [Function] { '0': false, '1': 'Invalid JSON response from server' } Invalid JSON response from server 

事情是,我从1路由调用函数,它工作得很好。 如果我从另一个单独的路由调用它,它会触发callback,但它表示callbackvariables(函数)是未定义的。

任何线索?

我build议你将参数logging到@invite函数中。 我怀疑是被调用了两次,一次是正确的参数,一次是由于程序中其他地方的错误造成的错误的参数。