Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View all currently active sessions in express.js

I found a similar question for many other languages - ASP.net, Django, etc... However, I am interested in Express.js over Node.js . How can I view all the sessions that are currently active?

like image 585
Erel Segal-Halevi Avatar asked Dec 24 '12 08:12

Erel Segal-Halevi


People also ask

How do I get all sessions in express-session?

The Session Store API has an optional all() method "used to get all sessions in the store as an array". You would call it like req. sessionStore. all((err, sessions)=>{ ... })

How do I check if a node session is active?

js var express = require('express'); var session = require('express-session'); var app = express(); After this, we have to initialize the session and we can do this by using following. app.

Where are sessions stored express?

Where is the session data stored? It depends on how you set up the express-session module. All solutions store the session id in a cookie, and keep the data server-side. The client will receive the session id in a cookie, and will send it along with every HTTP request.

What are sessions in express?

Express-session - an HTTP server-side framework used to create and manage a session middleware. This tutorial is all about sessions. Thus Express-session library will be the main focus. Cookie-parser - used to parse cookie header to store data on the browser whenever a session is established on the server-side.


2 Answers

The Session Store API has an optional all() method "used to get all sessions in the store as an array".

You would call it like req.sessionStore.all((err, sessions)=>{ ... })

I just tried to use it but it's optional and the memcached driver (in my case) doesn't implement it.

The other way is to bypass this, and query the store technology itself if possible. Hitalo's answer is one example of this approach.

like image 79
scipilot Avatar answered Oct 27 '22 05:10

scipilot


I would look into the store you use for session data, unless you use cookies to actually store all session data, not just the session id.

Maybe there is a way to access the list of sessions regardless of where you store session data, but I think that there isn't. But I might be wrong here.

Express Session API is described here, in case you couldn't find it (I spent a lot of time to figure out that many Express objects are actually Connect objects and documented there). But you probably knew it...

like image 36
esp Avatar answered Oct 27 '22 07:10

esp