Answer the question
In order to leave comments, you need to log in
Express 4 + socket.io + connect-mongo. How to get data from session in socket events?
Greetings.
I store sessions in base. For this I use 'connect-mongo'.
How to get data from session inside socket event? For example, when connecting a socket, you need to take the user's login from the session and send an event to the client.
io.on('connection', function(socket){
var username = /* тут нужно получить данные из сессии*/
socket.emit('welcome','Привет, ' + username);
});
Answer the question
In order to leave comments, you need to log in
stackoverflow.com/questions/25532692/how-to-share-...
Super simple solution. It's strange that it's hard to find.
The example in the link uses Redis, but it also works for mongoDB.
Here it is described how to do it for Express 3, and here is an example. I think for the 4th version it will not be a problem to finalize.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question