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?
3 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.

- 6,681
- 1
- 46
- 65
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...

- 7,314
- 6
- 49
- 79
This code build a route that returns an array of all saved sessions.
If you are using express
with express-session
module.
router.get('/sessions', (req, res) => {
req.sessionStore.sessionModel.findAll()
.then(sessions => sessions.map(sess => JSON.parse(sess.dataValues.data)))
.then((sessions) => {
res.send(sessions)
})
})

- 51
- 5