如何在Node.js中使用coffeescript访问全局变量

时间:2014-04-07 14:45:52

标签: javascript node.js coffeescript

我想在咖啡脚本中设置并获取对象的值。我的代码看起来像

global.fbUserData = ''

unless fbUserData

  #Use facebook strategy
  passport.use new FacebookStrategy(
  clientID: 'XXXXXX'
  clientSecret: 'XXXXXX'
  callbackURL: 'http://localhost:com/auth/facebook/callback'
  , (accessToken, refreshToken, profile, done) ->
      fbUserData.name = profile.displayName
      fbUserData.email = profile.emails[0].value
    done null, profile
  )

当在Facebook回调路线中我想访问global fbUserData对象时,它返回我未定义的

app.get "/auth/facebook/callback", passport.authenticate("facebook",
failureRedirect: "/user"
), (req, res) ->
     res.send "User Name " + fbUserData.name + " User Email " + fbUserData.email

此处fbUserData.namefbUserData.email未定义。如何设置变量值并在同一页面上获取所需的值?

0 个答案:

没有答案