Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Trouble with getting the session information #175

rahulkgupta opened this Issue · 9 comments

6 participants


Hey I'm trying to get the session information with now, which I learned is possible under v 0.8.
The changelog says that it should be simple, so I initialized my server like so.

var everyone = nowjs.initialize(app, {cookieKey:'mySecret'});

Then in an function, I do console.log(this.user.session) but I get Cannot read property 'session' of undefined

I'm sure I'm forgetting to do something.
Any help would be very much appreciated.


I have the same problem. I attempted to initialize like this:

var app =  express.createServer(
    express.session({ secret: 'mySecret' })

But this does not seem to work either, perhaps it needs to be combined with how you did it above.


I did that as well. :/ No luck.


hey rahulkgupta,

cookieKey doesn't refer to your secret, but rather the the name of the cookie if you had changed to from the default of connect.sid.

Otherwise, we are exploring reports of sessions not working properly so look for a fixed release soon.


Oops actually I read @DungFu 's comment incorrectly. I set the cookiekey to the key value in express.session.
I just recently got it to work. I don't know how I fixed it, but I suspect it has to do w/ me maybe making the mistake of using the this variable in a callback within a now function. Regardless, it works like a charm now. Thanks!


@ericz any words on if there was and issue, i seem to be having some troubles not sure if its something i am doing or not


This is what I am doing and it is working.

app.use(express.session({ secret: "keyboard cat" , key : 'myKey'}));

var everyone = nowjs.initialize(app, {cookieKey:'myKey'});`

and the now functions are defined in app.
Furthermore, make sure that you are not using this.user.session in some callback. I think that won't work.
So, the first thing I did in my now function was
var userId = this.user.session.userId;


@rahulkgupta: see the rest of this comment for reasoning as to why you can't reference this.user.session in a callback.

Javascript "fun fact": this refers to the context in which a function was called. Your callbacks are called in a different context than the original function, so they rebind the this variable.

In order to use this in a callback, you must take advantage of closures. This is often referred to as the that trick: basically, just create a local variable (e.g. var self = this;) and use self in your callbacks instead of this.

Example: = function () {
  var self = this; () {
    console.log(, "acknowledged.");

Yea that's what I'm doing.


I'm also having this same issue as @rahulkgupta

@ghost Unknown referenced this issue

nowjs.sessions is empty #184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.