Skip to content

Instantly share code, notes, and snippets.

@nanodeath
Created October 30, 2011 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanodeath/1326031 to your computer and use it in GitHub Desktop.
Save nanodeath/1326031 to your computer and use it in GitHub Desktop.
Sharing session store between http and non-http in node.js
{MemoryStore} = require('connect').session
sessionStore = new MemoryStore
app.configure ->
app.use express.session({secret: "my_super_secret", store: sessionStore})
app.configure ->
# ...
app.use express.session({secret: "my_super_secret"})
# ...
everyone.now.playerJoined = () ->
sid = unescape(@user.cookie["connect.sid"]) # you DO have to unescape the session id!
sessionStore.get(sid, (err, sess) ->
console.log("That player who joined? his userId is #{sess.userId}")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment